Save an Image to the iOS Photo Album/Camera Roll?


#1

If I have an Image, I can use the PNGImageFormat class to write it as a File in some directory. Is there some similar way to use JUCE to save it to the iOS Photo Album/Camera Roll instead?


#2

I found a solution in this old thread

http://juce.com/viewtopic.php?f=6&t=8493

A quick modification of one of the old functions yields this

[code]void saveToPhotosAlbum (const Image& imageToSave) {
JPEGImageFormat jpgff;
MemoryOutputStream mos;
jpgff.writeImageToStream (imageToSave, mos);

UIImage* im = [UIImage imageWithData: [NSData dataWithBytes: mos.getData() length: mos.getDataSize()]];
im = [UIImage imageWithCGImage: im.CGImage scale: 1.0f orientation: UIImageOrientationUp];
UIImageWriteToSavedPhotosAlbum (im, nil, nil, nil);

}[/code]

I’m not sure if that “scale: 1.0f” should actually be “scale: Desktop::getInstance().getDisplays().getMainDisplay().scale” or something, but at any rate it works well enough so far.