Wednesday, November 25, 2009

From Image to Image: The best of both worlds

Ax offers the Image class for manipulation of bitmap images. This class has some nice features, like cropping, rotating, changing the image size, ...

On the other hand, we can use CLR Interop. That way, we can use the Windows builtin functions to manipulate images.

And maybe, you want a bit of both. In that case, you can start with the Image class in Ax, and pass the image along to your CLR object and modify it even further. You can do this by using following code:

static void Image2Image(Args _args)
{ Image AxImage;
System.Drawing.Image ClrImage;
System.IntPtr ImagePtr;
;
AxImage = new Image();
AxImage.loadImage(@'C:\MyBitmap.bmp');
ImagePtr= new System.IntPtr(AxImage.exportBitmap());
ClrImage = System.Drawing.Image::FromHbitmap(ImagePtr);
}

We use the ExportBitmap method on the Image class in Ax, to get a pointer to the Image object.
With this pointer, we instantiate the Image CLR object. No need to save the image into an intermediate file, or reload the data from file.

No comments:

Post a Comment