아이폰어플개발정보2010. 10. 23. 03:40
[아이폰 앱 개발] save it as a file after downloading image

Download an Image and Save it as PNG or JPEG in iPhone SDK

Here is a quick example to save an image as JPEG or PNG. In this tutorial, I’m getting the image from the Internet then I’m saving it as JPEG and PNG.

Key points:

  • NSData to retrieve the image from the URL
  • NSDocumentDirectory to find Document folder’s Path
  • UIImagePNGRepresentation to save it as PNG
  • UIImageJPEGRepresentation to save it as JPEG

        NSLog(@"Downloading...");
        // Get an image from the URL below
        UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.objectgraph.com/images/og_logo.png"]]];
 
        NSLog(@"%f,%f",image.size.width,image.size.height);
 
        // Let's save the file into Document folder.
        // You can also change this to your desktop for testing. (e.g. /Users/kiichi/Desktop/)
        // NSString *deskTopDir = @"/Users/kiichi/Desktop";
 
        NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
 
        // If you go to the folder below, you will find those pictures
        NSLog(@"%@",docDir);
 
        NSLog(@"saving png");
        NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
        NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
        [data1 writeToFile:pngFilePath atomically:YES];
 
        NSLog(@"saving jpeg");
        NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpeg",docDir];
        NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
        [data2 writeToFile:jpegFilePath atomically:YES];
 
        NSLog(@"saving image done");
 
        [image release];

Download Sample XCode Project from here


http://blog.objectgraph.com/index.php/2010/04/05/download-an-image-and-save-it-as-png-or-jpeg-in-iphone-sdk/

Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 10. 12. 05:14
when textview empty, detecting it and disabling Button
In response to Victor Alexander on May 22, 2010 7:29 PM

This is what the 'delegate' property of the UITextField (or UITextView) is for. Then implement the appropriate delegate method so you get notified each time the field is changed. Then call your 'disabled' method from there.

In response to RickMaddy on May 22, 2010 11:47 PM

@RickMaddy thanks! So I'm really close... I know I'm missing something but I'm not quite sure what it is.

in my .h file I added my delegate to the view controller


UIViewController <UITextViewDelegate> 

I also added the following instance method that should tell the delegate that the text or attributes in the specified text view changed.


-(void)textViewDidChange:(UITextView *) textView1; 

In my .m file

I added a condition to the method above:


- (void) textViewDidChange:(UITextView *)textView1{      if (textView.text.length == 0) {           //disable button           moreButton.enabled = false;      }      else {           //enable button           moreButton.enabled = true;      } } 

I know that I'm missing something related to my delegate, but I'm not quite sure how to work this... even though I've read the documentation :/ Sorry to keep asking!


@property(nonatomic, assign) id<UITextViewDelegate> delegate 
In response to Victor Alexander on May 23, 2010 6:16 AM

"I'm not quite sure how to work this."

Two observations:

One, you have a typo.

You use textView1 as the parameter, and in the body of the method you use textView.

Two, connect the UITextView's delegate to you custom view controller class.

Try this:

  1. Open the view containing the UITextView.
  2. Double click on the View icon in the document window  to make sure the view is open in its editor window.
  3. Select the UITextView.
  4. Open the inspector to the Connections pane (cmd-2).

  5. Make a connection from the delegate to the File's Owner. Just click the delegate outlet and drag to the File's Owner icon the in the document window. Afte dragging you should see something like this:

  6. Save the nib file.
In response to Jeremy French on May 23, 2010 8:20 AM

Or if you are not using IB then in your view controller's 'viewDidLoad' method add the line 'textView.delegate = self'.







https://devforums.apple.com/message/223850

Posted by 오늘마감

댓글을 달아 주세요

아이폰뉴스2010. 8. 22. 19:58
[링크] 스티브 잡스의 '13년 매직'…애플, IT 황제 등극

스티브 잡스의 '13년 매직'…애플, IT 황제 등극

네이트 뉴스 링크: http://news.nate.com/view/20100527n19841?mid=n0600



출처 : http://blog.naver.com/PostView.nhn?blogId=baek2187&logNo=150087063814
Posted by 오늘마감

댓글을 달아 주세요