Contents
UNDER CONSTRUCTION |
netFreeImage
Overview
netFreeImage is a Dyalog cover class for bitmap resizing, cropping, compression and format change using .Net. It is using an open source project called FreeImage created by Floris van den Berg originally written in C++. The project is maintained today by Hervé Drolon. The .Net wrapper is the work of Jean-Philippe Goerke and Carsten Klein.Original project location FreeImage.NET wrapper project page A Beginners Guide to Bitmaps
netFreeImage supports:
- Loading and saving of as many bitmap types as possible
- Easy access to bitmap components, such as palettes, data bits and metadata
- Converting bitmap’s bit depths from one to another
- Accessing pages in a bitmap when there are multiple, such as in TIFF
- Basic manipulation of bitmaps, such as rotation, flipping and resampling or point operations such as brightness and contrast adjustment
- Alpha compositing and alpha blending
netFreeImage does not support:
- Advanced image processing operations such as convolution and transforms
- Bitmap drawing
- Vector graphics
For this class to work you need to download the original dll in C++ (FreeImage.dll) and the .Net wrapper (FreeImageNET.dll) and copy them both in the same directory as the dyalog.exe program. For commodity the version 3.17.04 of the dlls can be downloaded here: FreeImage.NET_3.17.0.4.zip
Instantiating and Disposing of the class:
bmp ← ⎕NEW netFreeImage ⍝ Instantiate the class. bmp.Dispose ⍝ To do when finish using the class to release the memory.
Methods to Load and Save a Bitmap
LoadFromFile ⍝ Get a FreeImageBitmap object from a file on disk. LoadFromBase64 ⍝ Get a FreeImageBitmap object from a Base64 string. LoadFromMemoryStream ⍝ Get a FreeImageBitmap object from a MemoryStream. LoadFromBitmap ⍝ Get a FreeImageBitmap object from a System.Drawing.Bitmap (WindowsForms). SaveToFile ⍝ Save the loaded bitmap to a file on disk with default values (format conversion allowed). SaveToBase64 ⍝ Save the loaded bitmap to a Base64 character vector with the current bitmap format. SaveToBase64WithFormat ⍝ Save the loaded bitmap to a Base64 character vector with the specified bitmap format. SaveToMemoryStream ⍝ Save the loaded bitmap to a MemoryStream object with the current bitmap format. SaveToMemoryStreamWithFormat ⍝ Save the loaded bitmap to a MemoryStream object with the specified bitmap format. SaveToBitmap ⍝ Save the loaded bitmap to a System.Drawing.Bitmap (WindowsForms). SaveToHtml ⍝ Save the loaded bitmap to an HTML inline image with the current bitmap format. SaveToHtmlWithFormat ⍝ Save the loaded bitmap to an HTML inline image with the specified bitmap format. SaveTo4bppBmpFile ⍝ Save the loaded bitmap to a 4 bit per pixel bmp file. SaveTo8bppBmpFile ⍝ Save the loaded bitmap to a 8 bit per pixel bmp file. SaveTo4bppPngFile ⍝ Save the loaded bitmap to a 4 bit per pixel png file. SaveTo8bppPngFile ⍝ Save the loaded bitmap to a 8 bit per pixel png file. SaveToJpegFile ⍝ Save the loaded bitmap to a jpeg file with optional options. SaveToTiffFile ⍝ Save the loaded bitmap to a tiff file with optional options. SaveToPngFile ⍝ Save the loaded bitmap to a png file with optional options.
Methods for Bitmap operation
AdjustBrightness ⍝ Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount. AdjustColors ⍝ Adjusts an image's brightness, contrast and gamma as well as it may optionally invert the image within a single operation. AdjustContrast ⍝ Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount. AdjustGamma ⍝ Performs gamma correction on a 8-, 24- or 32-bit image. ConvertTo4Bits ⍝ Converts the loaded bitmap to 4 bits per pixel using the default quantize algorithm. ConvertTo8Bits ⍝ Converts the loaded bitmap to 8 bits per pixel using the default quantize algorithm. ConvertTo16Bits ⍝ Converts the loaded bitmap to 16 bits per pixel. ConvertTo24Bits ⍝ Converts the loaded bitmap to 24 bits per pixel. ConvertTo32Bits ⍝ Converts the loaded bitmap to 32 bits per pixel. ConvertToGreyscale ⍝ Converts the loaded bitmap to Greyscale and 8 bits per pixel. ConvertToThumbnail ⍝ Converts the loaded bitmap to a thumbnail. Crop ⍝ Crop the loaded bitmap. FlipHorizontal ⍝ FlipHorizontal the loaded bitmap. FlipVertical ⍝ FlipVertical the loaded bitmap. Invert ⍝ Invert the loaded bitmap. Resize ⍝ Resize the loaded bitmap. Rotate ⍝ Rotate the loaded bitmap. SetResolution ⍝ Set the loaded bitmap to a new resolution (dpi). JPEGCrop ⍝ Performs a lossless crop on a JPEG file. JPEGTransform ⍝ Performs a lossless rotation or flipping on a JPEG file.
Methods for Pixel Access
GetPalette ⍝ Get the colors of the palette of loaded bitmap if existing. GetPixelsColors ⍝ Get the RGB colors for all pixels of loaded bitmap. GetSinglePixelColor ⍝ Get the RGB value of a single pixel.
Methods for Bitmap Information
GetMetaData ⍝ Get a Key/Value pair for each MetaData of the loaded bitmap. Info ⍝ Show information about the loaded bitmap. SetComment ⍝ Sets the comment of the loaded bitmap. Supported formats are JPEG, PNG and GIF. Show ⍝ Show the loaded bitmap in a WPF window. ShowInWebBrowser ⍝ Show the loaded bitmap in WindowForm browser using 'SaveToHtml'.
Utility methods
CaptureWpfVisual ⍝ Capture a WPF visual element to a FreeImageBitmap. FileToBase64String ⍝ Converts a bitmap, icon or cursor file to a Base64 String. CursorFromBase64String ⍝ Converts a Base64String to a cursor. ImageFromBase64String ⍝ Converts a Base64String to a System.Windows.Media.Imaging.BitmapImage (WPF).
Known limitations
Not all possibilities are coded in the netFreeImage class.
How to install netFreeImage in your workspace
Download netFreeImage.v1.0.txt
- Do a Select all (Ctrl+A) and a copy (Ctrl+C).
In your workspace execute )ed ○ netFreeImage
- Paste (Ctrl+V) the text into the Dyalog editor
- Press Escape and ')save' your workspace
Download FreeImage.NET_3.17.0.4.zip
Unzip and install FreeImage.dll and FreeImageNET.dll in the dyalog.exe directory
Test Run
Version Information
Version 1.0 April 2016, Pierre Gilbert
Original author: |
Pierre Gilbert |
Responsible: |
|
Email: |
<apgil AT SPAMFREE videotron DOT ca> |