1
我想使UIImage的觸摸像素透明。 我看到iPhone Objective C: How to get a pixel's color of the touched point on an UIImageView?在Iphone中使圖像的觸摸區域透明
使用該代碼,我可以找到圖像觸摸像素。但我不知道如何使像素透明並更新UIImage。
請幫幫我。
我想使UIImage的觸摸像素透明。 我看到iPhone Objective C: How to get a pixel's color of the touched point on an UIImageView?在Iphone中使圖像的觸摸區域透明
使用該代碼,我可以找到圖像觸摸像素。但我不知道如何使像素透明並更新UIImage。
請幫幫我。
希望這些可以幫助
What is the fastest way to draw single pixels directly to the screen in an iPhone application? 從這個SO質疑 How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
+ (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)xx andY:(int)yy count:(int)count
{
NSMutableArray *result = [NSMutableArray arrayWithCapacity:count];
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
int byteIndex = (bytesPerRow * yy) + xx * bytesPerPixel;
for (int ii = 0 ; ii < count ; ++ii)
{
CGFloat red = (rawData[byteIndex] * 1.0)/255.0;
CGFloat green = (rawData[byteIndex + 1] * 1.0)/255.0;
CGFloat blue = (rawData[byteIndex + 2] * 1.0)/255.0;
CGFloat alpha = (rawData[byteIndex + 3] * 1.0)/255.0;
byteIndex += 4;
UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[result addObject:acolor];
}
free(rawData);
return result;
}
非常感謝你 – rat 2011-04-16 14:22:51