Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS get width height of jpg file

In my iOS app, I'm downloading jpeg images from the web, and I'm wondering how to find the correct width and height of the image so I can display it properly in my iOS app.

For example,
enter image description here

How do I get the width and height of this jpg image?

like image 295
Rohan Agarwal Avatar asked Jan 31 '13 07:01

Rohan Agarwal


2 Answers

you can get Image Height and Width like:-

NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
NSLog(@'image height: %f',image.size.height);
NSLog(@'image width: %f',image.size.width); 

UPDATE:-

as per your URL you can get like:-

NSString *ImageURL = @"http://gigaom2.files.wordpress.com/2013/01/teacher-classroom.jpg";


    ImageURL =[ImageURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

    NSLog(@"img url ==%@",ImageURL);
    NSURL *imageUrl =[NSURL URLWithString:ImageURL];
    NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
    UIImage *image = [UIImage imageWithData:imageData];
    [inView setImage:image];
    NSLog(@"image height: %f",image.size.height);

    [lbl1 setText:[NSString stringWithFormat:@"%2.0f",image.size.height]];
    [lbl2 setText:[NSString stringWithFormat:@"%2.0f",image.size.width]];

your Screen look like:-

enter image description here

I just Create a Demo for You :) link is bellow

http://www.sendspace.com/file/7pp63a

like image 53
Nitin Gohel Avatar answered Oct 06 '22 23:10

Nitin Gohel


UIImage has the property size

image.size.width
image.size.height
like image 42
Inder Kumar Rathore Avatar answered Oct 06 '22 21:10

Inder Kumar Rathore