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 02-03-2012, 12:31 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 21
learningtocode is on a distinguished road
Default Flatteing UIImages and Saving to Camera Roll

I am trying to create a fun photo app. So far I have used UIPIckerViewController to pull up the camera/photo libarary and then load it to a UIImage View. I also have another UIImageView with a preloaded clipart (hat) that has UIGestures set. What I am trying to do now is load other customized clipart like hair, and sunglasses to the original picture and then save them to the camera roll. Am I headed in the right direction? and How should I go about doing this?
learningtocode is offline   Reply With Quote
Old 02-03-2012, 01:42 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

If it was me, I'd create a blank UIVIew called canvas and add the UIImageView and all my other clip art to that and then take a picture of it using canvas.layer renderInContext.

Here is the code to take a picture, just instead of self use canvas or whatever your view is named.
Code:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
    UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
Code copied and pasted from http://stackoverflow.com/questions/8...-specific-area
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 02-03-2012 at 01:48 AM.
Domele is offline   Reply With Quote
Old 02-03-2012, 08:25 AM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jacklee440 View Post
What I am trying to do now is load other customized clipart like hair, and sunglasses to the original picture and then save them to the camera roll. Am I headed in the right direction? and How should I go about doing this?
Domele gave you code that would let you flatten the contents of a "canvas" view into an image that contains all the different subviews combined.

in other words, he gave you a solution to what you are trying to do.

Set up a container view. Let's call it canvasView. In that view, add the image view the user picked as a subview. Also add views for hats, mustaches, hair, big ears, whatever. Let the user manipulate as desired.

Once you are ready to save, use the code Domele posted to flatten the canvas view and it's subviews into an image, and save that.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-03-2012, 09:16 AM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Lol, Duncan, that wasn't the OP asking again. That was a bot copying his post.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 02-03-2012, 09:33 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Domele View Post
Lol, Duncan, that wasn't the OP asking again. That was a bot copying his post.
Wow, really? Bots are smart enough now to extract sentences from posts and re-post them? Impressive.

What the he|| is the point of such a thing? Trying to get us to click the links in the sig? Seems awfully lame.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-03-2012, 09:40 AM   #6 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 21
learningtocode is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
If it was me, I'd create a blank UIVIew called canvas and add the UIImageView and all my other clip art to that and then take a picture of it using canvas.layer renderInContext.

Here is the code to take a picture, just instead of self use canvas or whatever your view is named.
Code:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
    UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
Code copied and pasted from objective c - Programmatically take a screenshot of specific area - Stack Overflow
Thank you so much. I will give it a shot this afternoon!
learningtocode is offline   Reply With Quote
Old 02-03-2012, 09:41 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 21
learningtocode is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Wow, really? Bots are smart enough now to extract sentences from posts and re-post them? Impressive.

What the he|| is the point of such a thing? Trying to get us to click the links in the sig? Seems awfully lame.
Crazy huh! Thanks for your input
learningtocode is offline   Reply With Quote
Old 02-07-2012, 07:06 PM   #8 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 21
learningtocode is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
If it was me, I'd create a blank UIVIew called canvas and add the UIImageView and all my other clip art to that and then take a picture of it using canvas.layer renderInContext.

Here is the code to take a picture, just instead of self use canvas or whatever your view is named.
Code:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
} else {
    UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
Code copied and pasted from objective c - Programmatically take a screenshot of specific area - Stack Overflow
I implemented your code and have successfully saved my images into my camera roll. The only thing now is I am getting my "Title Bars" in the image that is saved to the camera roll. Is there a way to customize the area of the initial picture?
learningtocode is offline   Reply With Quote
Old 02-07-2012, 09:52 PM   #9 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Did you create a specific view for your image and all of its "accessories?" If so, you need to replace self.view with self.canvas or whatever your view is named.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 02-09-2012 at 12:14 AM.
Domele is offline   Reply With Quote
Old 02-09-2012, 12:08 AM   #10 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 21
learningtocode is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
Did you create a specific view for your image and all of it's "accesories?" If so, you need to replace self.view with self.canvas or whatever your view is named.
that did it! thank you so much!!!
learningtocode is offline   Reply With Quote
Old 02-13-2012, 05:17 PM   #11 (permalink)
Registered Member
 
Keys's Avatar
 
Join Date: Jun 2010
Location: Edinburgh, UK
Posts: 62
Keys is on a distinguished road
Default

Question for screen captures that flatten... I'm using the following code which i have managed to get the size of the screen capture to work, however it starts from the top of the screen... how do i define where the screen capture starts from. i.e. if i have a toolbar at the top i want the screen capture at 60 pixels down + size i define?

THis is part of the code I'm using

background is the 'size' of the capture i want, but its cutting the wrong bit out of self!


UIGraphicsBeginImageContext(Background.bounds.size );
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];



Also any idea how to get it to capture in retina display as i believe it is capturing at the old 320 x 480 dimensions..

Last edited by Keys; 02-13-2012 at 05:44 PM.
Keys is offline   Reply With Quote
Reply

Bookmarks

Tags
uipickercontroller saving

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: 400
17 members and 383 guests
Atatator, chiataytuday, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, QuantumDoja, reficul, Retouchable, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

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