-1

In my APP, user is going to upload an UIImage. But I need to make sure the image is larger than 50*50 and smaller than 400*400 pixels. How could I do that?

I found out for a certain UIImage object, CIImage Property has .Height, .Width and .bitsPerPixel properties and I'm not sure whether these are relevant. I noticed that all these properties are relate to bitmap, but I have no experience of bitmap.

Thank you in advance.

PiyushRathi
  • 956
  • 7
  • 21
Todanley
  • 468
  • 3
  • 12

1 Answers1

-1

You can use:

CGImageRef cgimage = image.CGImage;

size_t pixelsWide  = CGImageGetWidth(cgimage);
size_t pixelsHigh = CGImageGetHeight(cgimage);

Swift:

var bitmapByteCount = 0
  var bitmapBytesPerRow = 0

  //Get image width, height in pixel
  let pixelsWide = CGImageGetWidth(inImage)
  let pixelsHigh = CGImageGetHeight(inImage)

And do your validation like:

if (pixelsWide >=50 && pixelsWide <=400)
{
if (pixelsHigh >=50 && pixelsHigh <=400)
 {
   // Add your code here. 
 }
}

For getting more details:

Check the SO post:

How to get Pixel data from UIImage?

Please put look on Getting the raw data

Community
  • 1
  • 1
Saranjith
  • 11,242
  • 5
  • 69
  • 122
  • Thanks for help. I just tested your answer with the other one, which using size property of an UIImage Instance. I used image.size.width * image.scale . And the result is exactly the same as you method. Just wondering are they basically the same thing? And can I say for sure the results are actual pixel instead of iOS points? Because I heard that number of pixel may equal 2* or 3* points. – Todanley Dec 12 '16 at 12:09