2
votes

I need to export the images stored in CompanyImage table to a image files.

How can I do it?

Reading the table I obtain a Bitmap field but how to know the type of image to build the correct extension and save it to file?

2

2 Answers

4
votes

Finally I found the solution.

To export the image from CompanyImage:

    // Grant clrinterop permission.
    new InteropPermission(InteropKind::ClrInterop).assert();

    image = new Image();
    image.setData(companyImage.Image);

    result = image.saveImage(@"c:\test.jpg",3);

    CodeAccessPermission::revertAssert();

To know the original type:

    image.saveType();
0
votes

The above code wouldn't work right away. Here's the code that would run:

bindata bin = new bindata();
str content;
container image;
CompanyImage companyImage;
;

select companyImage;
image = companyImage.Image;
bin.setData(image);

content=bin.base64Encode();

AifUtil::saveBase64ToFile("c:\\temp\\test.tif", content);