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 03-25-2011, 12:04 PM   #1 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Cool Save to Iphone images

Hi ,
I have a button creator.
You can choose the alpha , saturation etc.
You can also enter a name/text in a textfield and it will display it on a label (on the button).
Actually you could create a custom button with custom text on it.
How do I have to do that you can save the button layer + the label layer together ?
Thanks very much !
sacha1996 is offline   Reply With Quote
Old 03-25-2011, 03:51 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

if you need to show the image only on your app, you can just save the uibutton frame together the image (so that you can re-add it every time you show the image), if you need to create an image that include the button, you can get a screenshot, but you have only a low-res image.

Code:
UIImage *viewImage = [UIImage imageWithCGImage:UIGetScreenImage()];
__________________

Last edited by dany_dev; 03-25-2011 at 04:38 PM.
dany_dev is offline   Reply With Quote
Old 03-26-2011, 05:08 AM   #3 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Cool

Quote:
Originally Posted by dany_dev View Post
if you need to show the image only on your app, you can just save the uibutton frame together the image (so that you can re-add it every time you show the image), if you need to create an image that include the button, you can get a screenshot, but you have only a low-res image.

Code:
UIImage *viewImage = [UIImage imageWithCGImage:UIGetScreenImage()];
Thanks !
But I need to save the button layer with the label layer together.
The screenshot will have all my window , but the button is only a part of it , so you will see all the other things, and it is low-res as you said

Any idea what's the code for to save only the button layer (wich I know) , but the code for the button layer with the label layer , do you know it (I don't know) ?

Last edited by sacha1996; 03-26-2011 at 07:41 AM.
sacha1996 is offline   Reply With Quote
Old 03-26-2011, 06:24 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

maybe i missunderstood the question.

I thinked initially that you're searching a way to save your image + a button on it.

Now i understand that you need to save only a button + a label. But you need to do that in an image? or you can just save button frame and label text and then re-show it?
__________________
dany_dev is offline   Reply With Quote
Old 03-26-2011, 07:39 AM   #5 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Post

Quote:
Originally Posted by dany_dev View Post
maybe i missunderstood the question.

I thinked initially that you're searching a way to save your image + a button on it.

Now i understand that you need to save only a button + a label. But you need to do that in an image? or you can just save button frame and label text and then re-show it?

I don't really understand what you mean. But let's say like that :
It's a button maker. You choose the button text , alpha , saturation etc.
After you made the button you sould save him to you image. When I do that it's saves only the button layer , but not the label layer.
I want to save the button frame + the label text together with no background (so in alpha).
I have the code for to save the button., but i don't know the code for to save the label in the button image.
Do you want that I let see the code for to save the button layer only ?
sacha1996 is offline   Reply With Quote
Old 03-26-2011, 07:59 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

ok...show it.
__________________
dany_dev is offline   Reply With Quote
Old 03-27-2011, 04:08 AM   #7 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Post

Quote:
Originally Posted by dany_dev View Post
ok...show it.
Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(_button.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[_button.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.frame.size.height)};
	
	[[UIColor clearColor] set];
	
	for (int i = 0; i < 2; i++) {
		UIRectFill(overDrawRects[i]);
		CGContextSaveGState(theContext);
		CGContextClipToRect(theContext, overDrawRects[i]);
		CGContextTranslateCTM(theContext, -1, 0);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}


-(IBAction) saveTapped:(id)sender {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	
	// the path to write file
	NSString *buttonFile = [documentsDirectory stringByAppendingPathComponent:@"button.png"];
	NSString *buttonHighlightFile = [documentsDirectory stringByAppendingPathComponent:@"button-highlight.png"]; 
	
	[self saveImageToFile: buttonFile];
	
	
	
	[_button setHighlighted:YES];
	
	[self saveImageToFile: buttonHighlightFile];
	
	[_button setHighlighted:NO];
	NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", documentsDirectory];
	UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[alertView show];
}
_button is the button to be saved , it saves only the _button layer.
I have also a UIlabel called label. I want this to be saved with the button frame together
Thanks !

Last edited by sacha1996; 03-27-2011 at 11:25 AM.
sacha1996 is offline   Reply With Quote
Old 03-28-2011, 11:20 AM   #8 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Has anyone any idea ???
Please helppppp
I really need to know the code !!
Thankyou
sacha1996 is offline   Reply With Quote
Old 04-02-2011, 03:00 AM   #9 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

add your button and label on a uiview and then change that line

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(_myNewLayer.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[_myNewLayer.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _myNewLayer.frame.size.height), CGRectMake(_myNewLayer.frame.size.width - 11, 0, 1, _myNewLayer.frame.size.height)};
	
	[[UIColor clearColor] set];
	
	for (int i = 0; i < 2; i++) {
		UIRectFill(overDrawRects[i]);
		CGContextSaveGState(theContext);
		CGContextClipToRect(theContext, overDrawRects[i]);
		CGContextTranslateCTM(theContext, -1, 0);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}
it should work.
__________________
dany_dev is offline   Reply With Quote
Old 04-02-2011, 10:33 AM   #10 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Thanks but what do you mean with add your button and label on a UIView , how do I have to do that.
I don't reallly understand what you mean with this Thankyou

Quote:
Originally Posted by dany_dev View Post
add your button and label on a uiview and then change that line

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(_myNewLayer.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[_myNewLayer.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _myNewLayer.frame.size.height), CGRectMake(_myNewLayer.frame.size.width - 11, 0, 1, _myNewLayer.frame.size.height)};
	
	[[UIColor clearColor] set];
	
	for (int i = 0; i < 2; i++) {
		UIRectFill(overDrawRects[i]);
		CGContextSaveGState(theContext);
		CGContextClipToRect(theContext, overDrawRects[i]);
		CGContextTranslateCTM(theContext, -1, 0);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}
it should work.
sacha1996 is offline   Reply With Quote
Old 04-02-2011, 10:39 AM   #11 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

[yourView addSubview:yourButton];
[yourView addSubview:yourLabel];

where yourView is a UIView that you allocated\initialized with a certain frame and added as subview of your self.view (where self represent your viewcontroller).

I hope is clear enough.
__________________
dany_dev is offline   Reply With Quote
Old 04-02-2011, 11:03 AM   #12 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Thanks for your time.
I did that and when i start the app , the window is white with nothing.
Something wrong with my code ?? :

In the .h:
Code:
@interface CoolButtonViewController : UIViewController {
    CoolButton *_button;
	IBOutlet UISlider *slider;
	IBOutlet UITextField *field;
	IBOutlet UILabel *label;
    UIView *view;
	
}

@property (retain) IBOutlet CoolButton *button;
@property (retain) IBOutlet UITextField *field;
@property(nonatomic, retain) IBOutlet UISlider *slider;
@property(nonatomic, retain) UIView *view;
in the .m ViewDidLoad:
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	field.delegate = self;
    UIView *view = [UIView alloc];
    [view addSubview:_button];
	[view addSubview:label];
	
}
in the .m the void :
Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(view.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[view.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, view.frame.size.height), CGRectMake(view.frame.size.width - 11, 0, 1, view.frame.size.height)};
	
	[[UIColor clearColor] set];
	
	for (int i = 0; i < 2; i++) {
		UIRectFill(overDrawRects[i]);
		CGContextSaveGState(theContext);
		CGContextClipToRect(theContext, overDrawRects[i]);
		CGContextTranslateCTM(theContext, -1, 0);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}
sacha1996 is offline   Reply With Quote
Old 04-02-2011, 12:39 PM   #13 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

first think that i see is not good:
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	field.delegate = self;
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [view addSubview:_button];
	[view addSubview:label];
	
}
i not checked the rest of the code.
__________________

Last edited by dany_dev; 04-03-2011 at 04:18 AM.
dany_dev is offline   Reply With Quote
Old 04-02-2011, 01:02 PM   #14 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Thanks but its still remains white
sacha1996 is offline   Reply With Quote
Old 04-03-2011, 04:17 AM   #15 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you haven't added it as subview of your view of your viewController (self.view), so you will never see that.
Moreover you are using property not in a good manner (read it), and you should not use view as name of your istance variable since that "view" is already the name of the view of the ViewController (self.view)

Code:
@interface CoolButtonViewController : UIViewController {
        CoolButton *_button;
	IBOutlet UISlider *slider;
	IBOutlet UITextField *field;
	IBOutlet UILabel *label;
        UIView *myView;
	
}

@property (retain) IBOutlet CoolButton *button;
@property (retain) IBOutlet UITextField *field;
@property(nonatomic, retain) IBOutlet UISlider *slider;
@property(nonatomic, retain) UIView *myView;

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
   field.delegate = self;
   
   UIView *viewTmp =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
   self.myView = viewTmp;
   [viewTmp release];

   [view addSubview:_button];
   [view addSubview:label];
   [self.view addSubview:myView];

}

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(self.myView.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[self.myView.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.frame.size.height)};
	
	[[UIColor clearColor] set];
	
	for (int i = 0; i < 2; i++) {
		UIRectFill(overDrawRects[i]);
		CGContextSaveGState(theContext);
		CGContextClipToRect(theContext, overDrawRects[i]);
		CGContextTranslateCTM(theContext, -1, 0);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}
ps: now your new view (myView) has a frame of the entire screen (320x480), you would probably reduce it to fit just your button+label.
__________________

Last edited by dany_dev; 04-03-2011 at 04:29 AM.
dany_dev is offline   Reply With Quote
Old 04-04-2011, 10:15 AM   #16 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Thanks , when I'm fitting the CGRect , the button is always moving with myView. So I take an image of that and the button is not inside because it's moving with the myView
But still thanks for the code !
sacha1996 is offline   Reply With Quote
Old 04-04-2011, 10:34 AM   #17 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by sacha1996 View Post
Thanks , when I'm fitting the CGRect , the button is always moving with myView. So I take an image of that and the button is not inside because it's moving with the myView
But still thanks for the code !
i don't understand what you say .

Using the code posted, when you do a screen, what you see inside it? uibutton + label or whatever?
__________________
dany_dev is offline   Reply With Quote
Old 04-04-2011, 10:44 AM   #18 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
i don't understand what you say .

Using the code posted, when you do a screen, what you see inside it? uibutton + label or whatever?
I typed your code and I when I let the cgrect on all the screen , I cannot tap another rounded rect button with IBaction. But when I reduce the cgrect of myView , I can tap the other rounded rect button.
But the problem is : when i reduce the cgrect , the _button moves from his original place , wich is why i cannot take a picture of the button
After reducing I see the label + _button on another place , but my originals things like my other button with UIButton (not related to myView) doens't change place

Thankyou for the code !
and for your time !
sacha1996 is offline   Reply With Quote
Old 04-04-2011, 11:40 AM   #19 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

so you must re-position the button and label

_button.center = CGPointMake(x,y);
_label.center = CGPointMake(x,y);
__________________
dany_dev is offline   Reply With Quote
Old 04-04-2011, 01:31 PM   #20 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
so you must re-position the button and label

_button.center = CGPointMake(x,y);
_label.center = CGPointMake(x,y);
Thanks but it still doesn't take the picture of the whole button.

that's my code currenly :
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	field.delegate = self;
    
    UIView *viewTmp =  [[UIView alloc] initWithFrame:CGRectMake(46, 61, 226, 46)];
    self.myView = viewTmp;
    [viewTmp release];

    _button.center = CGPointMake(120,40);
    label.center = CGPointMake(120,40);

    
    
    [myView addSubview:_button];
    [myView addSubview:label];
    [self.view addSubview:myView];
	
}
Maybe it will help you by looking at the picture taken from the app down :
Attached Images
File Type: png button.png (3.2 KB, 2 views)
sacha1996 is offline   Reply With Quote
Old 04-04-2011, 02:02 PM   #21 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

use some external service to upload image, maybe can help also if you can upload the project.
__________________
dany_dev is offline   Reply With Quote
Old 04-04-2011, 02:28 PM   #22 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
use some external service to upload image, maybe can help also if you can upload the project.
Hi thanks ,
I can send you the project , but wich external service is a good one ?
Please tell me
sacha1996 is offline   Reply With Quote
Old 04-04-2011, 05:10 PM   #23 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

http://imageshack.us/for images...
http://megaupload.com/for files....
__________________
dany_dev is offline   Reply With Quote
Old 04-05-2011, 12:35 AM   #24 (permalink)
Banned
 
Join Date: Apr 2011
Posts: 4
charlikl is on a distinguished road
Default

Thanks for sharing answers. I was searching for this answers from many times and posted this thread in many forums but i was not able to find out the answers. I think now it will help me out in my problems.
charlikl is offline   Reply With Quote
Old 04-05-2011, 10:28 AM   #25 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
I want to keep it private please.
By e-mail maybe ?
sacha1996 is offline   Reply With Quote
Reply

Bookmarks

Tags
button, label, layer, save image, sdk

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: 369
12 members and 357 guests
condor304, dansparrow, Domele, dre, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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