在目标C中,我是比较新的,可以将一个png图像转换成一个CGBitmapContext。如果是的话,我如何实现它。
发布于 2014-01-15 04:29:14
虽然不可能从UIImage获得像素值,但可以通过CGImage of UIImage访问像素值。看看文章中提供的this answer。它使用onTouch方法在用户手指所在的特定x和y坐标上获取RGB值。
发布于 2014-02-09 16:37:31
这就是我找到的解决办法
- (IBAction)handlePans:(UIPanGestureRecognizer *)event{
if (event.numberOfTouches==1){
tranx = [event locationInView:self].x;
trany = [event locationInView:self].y;
CGPoint vel = [event velocityInView:self];
velocityx = vel.x;
velocityy = vel.y;
// NSLog(@"x: %d y:%d", tranx,trany);
//NSLog(@"velocity x - %f", vel.x);
//NSLog(@"velocity y - %f", vel.y);
_imageselct = [UIImage imageNamed:@"GASOLINE.png"];
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(_imageselct.CGImage));
const UInt8* data = CFDataGetBytePtr(pixelData);
int pixelInfo = ((workingImage.size.width * trany) + tranx ) * 4;
float red = data[pixelInfo];
float green = data[(pixelInfo+1)];
float blue = data[pixelInfo + 2];
float alpha = data[pixelInfo + 3];
CFRelease(pixelData);
UIColor* color = [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];
if ([color getRed:&red green: &green blue: &blue alpha: &alpha]){
NSLog(@"r: %f g: %f b: %f a: %f", red, green, blue, alpha);
}
}
}https://stackoverflow.com/questions/21127998
复制相似问题