iphone - Retrieving a pixel alpha value for a UIImage -


I am currently trying to get the alpha value of pixels in a UIImageView. I have received CGI image from [UIImageView image] and created an RGBA byte array from this. Alpha is preplanned.

  CGIJJRF image = uiImage. CGImage; Width of NSUINTER = CGMJetWidth (image); NSUInteger height = CIggate height (image); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB (); RawData = malloc (height * width * 4); BytePrintPixel = 4; Bytespiro = bytepixel * width; NSUInteger BitsStechnicPoint = 8; CGContextRef Reference = CGBitmapContextCreate (raw data, width, height, bitsprinting, byteper, colorspace, KCGImAlphapremTiltlivedList; KCGITMAPOder32Big); CGColorSpaceRelease (colorspace); CGContextDrawImage (Reference, CGRectMake (0, 0, width, height), image); CGContextRelease (reference);  

I then calculate the array index for the given alpha channel using coordinates from UIImageView.

  int byteIndex = (Bitespiro * uiViewPoint.y) + UiViewPoint.x * BytePixel; Unsigned four characters = raw data [byteindex + 3];  

However, I do not get the values ​​that I expect. For the completely black transparent area of ​​the image, I get zero-zero values ​​for the alpha channel. Do I need to translate the coordination between UIKit and core graphics - that is: Is the y-axis inverted? Or have I already understood alpha values ​​wrong? . However, after setting the blend mode my alpha values ​​were what I expected:

  CGContextSetBlendMode (reference, kCGBlendModeCopy); Yes, points to CGContexts in the UIKit pointing y-axis. .  

Edit the code after reading:

You also want to set the blend mode to change before dragging the image, since you will see the image Let's assume alpha which was in the first reference buffer:

  CGContactTatbandmod (reference, KCGb and MODCopy);  

Edit after thinking:

You can make the least possible CGBitmapContext more efficient than building too (1x1 pixels? Maybe 8x8? Is a try) and translate it from the context before highlighting your desired position:

  cgiontacttranslatecmtm (reference, xoffet, ouafet);  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -