0

I need to know image dimensions before downloading it. I searched and found it is possible in .Net by reading the header of html response! Link

Can I do that in iPhone? If yes, How?

Thanks

Community
  • 1
  • 1
Fa.Shapouri
  • 988
  • 2
  • 12
  • 30
  • I would duplicate the .Net code in Objective-C if possible. HTTP is not my area of expertise but have you looked at the `NSURLRequest` documentation and especially the `allHTTPHeaderFields` and `valueForHTTPHeaderField:` methods? Link to documentation: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSURLRequestUseProtocolCachePolicy – Robotic Cat Jun 25 '13 at 11:48
  • The .Net link you pasted only retrieves the file size in bytes, not image dimensions. As others have said, you cannot know the pixel dimensions without downloading the file. Perhaps the closest you can get is to create a small REST service that returns image sizes for you, but then you would still need to wait for the REST service response to download. – faffaffaff Jun 25 '13 at 12:41

1 Answers1

0

You can not able to get the dimension of the image that is height and width before downloading the image. How ever you can get the size of image before downloading the image in the delegate method below is the code

 -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

    float expSize = 0;
    expSize = response.expectedContentLength;

}

where expSize is the size of the image.

Vinodh
  • 5,262
  • 4
  • 38
  • 68
Gyanendra
  • 361
  • 2
  • 15
  • 1
    I need the height of image, this method returens size of data – Fa.Shapouri Jun 25 '13 at 12:08
  • 1
    As i have mentioned height of the image you can not get before downloading. Since the images are stored in the server so you can get the height of the image from the server for that you can have a key value in webservice mentioning the height of the image then you can parse it through the key and you can get the image height. – Gyanendra Jun 25 '13 at 12:13