How to load and draw image from PhotoAlbum ?

Any example please how to draw image loaded from iPhone photo album ?

I see on the iOS OF Examples ( OF v0072_iOS_release) are only how to draw image from camera …and i modify the code to open the photo album but the app crash when i select the photo from photoalbum.
thanks.

Nobody can help me ?
I change the

  
camera.opencamera()  

to

  
camera.openLibrary()  

from imagePicker Example.
The app crash when i select the photo from photolibrary :

2012-11-20 12:09:51.997 ImagePickerExample[714:14c03] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Source type must be UIImagePickerControllerSourceTypeCamera’
*** First throw call stack:
(0x29e3012 0x2306e7e 0xe1751c 0xe17839 0x2f1fe3 0x231a9ff 0x2f124b 0x2f1207 0x42d3 0x1d7004 0x2cddb2 0x2c9074 0x882b90 0x29a2376 0x29a1e06 0x2989a82 0x2988f44 0x2988e1b 0x325b7e3 0x325b668 0xc1665c 0x2cbe0b 0x2cbc8b 0x1d4823 0x2f32 0x2e95)
libc++abi.dylib: terminate called throwing an exception
(lldb)

bump

I’m running into the same problem.
As far as I understand we cannot access images from a library in the same way we access camera images, which makes sense because open framework here actually needs that we wait until we’ve chosen an image and then retrieve that one. However, also cannot figure out what is the “right” way to do it… did you get any further?

@sure_m
No, I have not found a solution for this. No one is interested in my problem, and there is no example in iOS example apps how to get/write images from photoalbum.
:frowning:
I’m experimented with cinder and looks more promising than openframeworks. Also on Cinder forum you can find help and they respond to all beginners questions. I like openframeworks but support from the community is very poor… :frowning:
Sorry for my english.

I think I don’t agree on this too much, normally you get support here quite quickly. at least all my earlier question have ben answered :slight_smile:
good luck with cinder, I’ll dig deeper into the iOS storing mechanisms…

Apologies for the delay getting an answer to this question.
Here is an example of using the image picker to select an image from the library on iOS.

https://gist.github.com/4245137

Note there seems to be a bug with the de-allaocation of the image picker.
I’ll add the bug to the GH repo - but in the meantime try commenting out line 209 from ofxiPhoneImagePicker.mm

  
     //_imagePicker.cameraOverlayView = nil;   

Sorry to leave you guys hanging with this, going to get our iOS guy to cleanup the class and make it much clearer how to use it.

All the best!
Theo

thank you @theo

I commented the _imagePicker.cameraOverlayView = nil; but that does not change the xcode warning…
I try to allocate the “photo” in setup() method and work : photo.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA); This may not be the right solution,but the xcode allocate warnings has gone after this.

Hi Dorald!

Did you try the example I posted here: https://gist.github.com/4245137 ?

Maybe could you try running that example ( just take the iOS empty example and copy and replace the gist over the testApp.mm file ) and see if you still get the warning you were mentioning?

Also at some point it would be good to switch to 0073 as there a couple of bugs in 0072 which are not good for production code.

Hope it works!
Theo

I use OF 0073, Xcode 4.5.2, iOS 6.0.1 & iOS 5.1.1, commented

  
_imagePicker.cameraOverlayView = nil;  

, rebuild OF, create new project from projectGenerator, put your code posted on gist, and still got this warning message from xcode :

[warning] ofGLRenderer::draw(): texture is not allocated.

When i put this on setup() :

  
photo.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);  

the warnings disappear.

@theo: thanks for the reply. as said I had posted the same question here http://forum.openframeworks.cc/t/loading-image-from-ios-photo-library-with-ofxiphoneimagepicker/11498/1 (there is also my code).
thanks for the link. It does work but I am wondering how I can use the photo I’m choosing in my app?
(errors disappear with the github example, without even without uncommenting the “_imagePicker.cameraOverlayView = nil;” as you mentioned… so well done there but how do I use that photo in my app??)

UPDATE:
I think I figured it out myself. As I see when I touched next it was reopening the photo library so I just added a variable that I set false in the setup and as soon as the image is chosen I set it to true and don’t go to the opening the library any more… looks like this in the touchDown then

  
if(touch.id == 0){  
        if (ImageChosen==false) {  
            camera.openLibrary();  
            photo.setFromPixels(camera.pixels, camera.width, camera.height, OF_IMAGE_COLOR_ALPHA);  
            ImageChosen=true;        }  
          
          
       }  

Don’t know if that’s the most elegant way to deal with it but it seems to work… other suggestions welcome though… (also could I load several images into an array with only opening the photo library once?)

Ahh yeah - better not to allocate the photo image but just only draw it when the pixels have been filled.

  
if( photo.getWidth() >0 ){  
    photo.draw(0,0);  
}  

well now you have the image as an ofImage ( called ‘photo’ ).
So you can now draw it to the screen. You can resize it or do anything that ofImage can do.

What are you trying to do with the photo in your app?

1 Like

just updated my reply above. think it is solved for now. need to think about if this is useful for my purpose (as the user needs to pick the images, but I would rather want to load them automatically). Good learning experience anyways, I will check out the XML way and as it seems I could store the images as xmls and those could be read automatically right?

@theo, thank you very much for reply I appreciate your help !

It would be very helpful if in the iOS examples had load/writePhotoAlbumExample, retina/nonretinaExample, autorotateExample etc…
Thank you.

Hi Dorald!

No problem, I’m glad it helped.
We’ll look at adding some better examples for the library stuff - I added an issue here
https://github.com/openframeworks/openFrameworks/issues/1730

Please feel free to open an issue about other iOS examples you would like to see.

All the best!
Theo

Howdy,

I’m using 0.7.4 and failing to open the Library on either iPhone or iPad.
At touchDown I’m calling…

  
camera = new ofxiPhoneImagePicker();  
camera->setMaxDimension(max(ofGetWidth(),ofGetHeight()));  
camera->openLibrary();  

and am getting…

  
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type must be UIImagePickerControllerSourceTypeCamera'  

[tt]camera->openCamera()[/tt] works fine for me.

Any ideas where I’m going wrong?

Ed

hi @ed_burton.

To fix try to comment or delete the :

  
delete camera;  

inside testApp::update() method.
This works for me :wink:

Many thanks Dorald, commenting out “delete camera” did indeed fix it. I don’t understand why though. Doesn’t it leave behind a memory leak?

hi ed.

I really don’t understand the role of “delete camera” here if “camera->close()” doing the ‘work’ that is supposed to do. As for memory leak I see the imagepicker (close) inside ofxiPhoneImagePicker.m is deallocated in - (void)dealloc.

I expect more changes for iOS on OF_074. I hope that will be in the next OF version.