Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-15-2008, 07:56 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 73
SAG3194 is on a distinguished road
Default Saving an Image

Hey i have this code and for some reason it saves the entire view I only want to it save an image.....

- (IBAction)saveViewToPhotoLibraryid)sender {

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);

[self.view.layer renderInContext:ctx];

UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
UIGraphicsEndImageContext();
}
SAG3194 is offline   Reply With Quote
Old 11-15-2008, 08:57 PM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Sarcasm on

Let's see. You have a method called saveViewToPhotoLibrary. In this method you render the view to a graphics context. You then create an image with this context and save the image (representing the view) to the photo library.

Now why is it that you don't understand why it's saving the view?

Sarcasm off

If you just want to save an image to the photo library then just use the one line of code:

UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);

passing in the UIImage you actually want to save.

None of that other code is of any use for simply saving an image you already have.

HTH.

Rick
RickMaddy is offline   Reply With Quote
Old 11-15-2008, 09:08 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 73
SAG3194 is on a distinguished road
Default

- (IBAction)saveImageToPhotoLibraryid)sender {

UIImageWriteToSavedPhotosAlbum(image3.image, nil,nil,nil);

}

This doesn't work..
SAG3194 is offline   Reply With Quote
Old 11-15-2008, 09:12 PM   #4 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
scottiphone is on a distinguished road
Default

Recheck your code. Is the image valid and not 0? Has it been released? Are you retaining it while saving?
Step into the debugger.
scottiphone is offline   Reply With Quote
Old 11-15-2008, 09:14 PM   #5 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
PhoneyDeveloper is on a distinguished road
Default

Rick,

Don't you know anything?

This is the sarcasm tag:

<sarcasm>

It ends here:

</sarcasm>
PhoneyDeveloper is offline   Reply With Quote
Old 11-15-2008, 09:18 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 73
SAG3194 is on a distinguished road
Default

- (IBAction)saveViewToPhotoLibraryid)sender {

UIImageWriteToSavedPhotosAlbum(image3.image, self, (SEL)@selector(image:didFinishSavingWithError:cont extInfo, image.image);


[image release];
[image3 release];

}

Still Doesn't Work..
SAG3194 is offline   Reply With Quote
Old 11-15-2008, 09:50 PM   #7 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

SAG - Run your code in the debugger and confirm that image3 is a valid UIImageView and that its image is not null.

Phoney - I know, I'm embarrassed I didn't remember to use the right tags.

That's one black mark on my Geek card.
RickMaddy is offline   Reply With Quote
Old 11-15-2008, 09:52 PM   #8 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 73
SAG3194 is on a distinguished road
Default

macbook-pro-2.local NavBar[11732] <Error>: CGImageDestinationAddImage image parameter is nil\n


Sat Nov 15 22:18:33 macbook-pro-2.local NavBar[11732] <Error>: CGImageDestinationFinalize image destination does not have enough images\n

You were right... how do I make it so that it isn't nil?
SAG3194 is offline   Reply With Quote
Old 01-11-2009, 11:14 PM   #9 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 9
walaber is on a distinguished road
Default

UIImageWriteToSavedPhotosAlbum appears to use another thread to do the saving, so it errors if you release the image right after you call it.

to do it properly, you need to setup a function for it to call when saving is complete, and then release the image. the function for it to call should look like this:

Code:
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
...and then you call UIImageWriteToSavedPhotosAlbum like this:
Code:
UIImageWriteToSavedPhotosAlbum( theImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil );
walaber is offline   Reply With Quote
Old 07-07-2010, 08:56 AM   #10 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 22
kmadhukishore is on a distinguished road
Default

Can we do this for EAGLLayer???
I tried but I am getting black screen

Thanks,
Madhu.
kmadhukishore is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 376
7 members and 369 guests
daudrizek, HemiMG, Kirkout, MarkC, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0