使用触摸ios擦除imageView背景色的颜色
我试着这样做:我有一个带有图像的图像视图,我添加了另一个带有浅文本颜色背景的相同尺寸的图像视图。我需要清除/擦除上面图像中要擦除的部分。这样,从这一部分,下面的图像将是清晰的。附图一 当我移动触摸屏时,那个部分应该是清晰的。使用触摸ios擦除imageView背景色的颜色,ios,image-processing,Ios,Image Processing,我试着这样做:我有一个带有图像的图像视图,我添加了另一个带有浅文本颜色背景的相同尺寸的图像视图。我需要清除/擦除上面图像中要擦除的部分。这样,从这一部分,下面的图像将是清晰的。附图一 当我移动触摸屏时,那个部分应该是清晰的。 任何帮助请创建一个Scratch view类并将Scratch透明图像放入initMethod,如:- 并且还创建了第二个视图类,用于显示划痕后的背景图像 下面这个例子对您尝试以下方法非常有用:- 如何恢复图像中已擦除的部分? - (id)initWithFrame:(CG
任何帮助请创建一个Scratch view类并将Scratch透明图像放入initMethod,如:- 并且还创建了第二个视图类,用于显示划痕后的背景图像 下面这个例子对您尝试以下方法非常有用:-
如何恢复图像中已擦除的部分?
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
scratchable = [UIImage imageNamed:@"scratchable.jpg"].CGImage;
width = CGImageGetWidth(scratchable);
height = CGImageGetHeight(scratchable);
self.opaque = NO;
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
CFMutableDataRef pixels = CFDataCreateMutable( NULL , width * height );
alphaPixels = CGBitmapContextCreate( CFDataGetMutableBytePtr( pixels ) , width , height , 8 , width , colorspace , kCGImageAlphaNone );
provider = CGDataProviderCreateWithCFData(pixels);
CGContextSetFillColorWithColor(alphaPixels, [UIColor blackColor].CGColor);
CGContextFillRect(alphaPixels, frame);
CGContextSetStrokeColorWithColor(alphaPixels, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(alphaPixels, 20.0);
CGContextSetLineCap(alphaPixels, kCGLineCapRound);
CGImageRef mask = CGImageMaskCreate(width, height, 8, 8, width, provider, nil, NO);
scratched = CGImageCreateWithMask(scratchable, mask);
CGImageRelease(mask);
CGColorSpaceRelease(colorspace);
}
return self;
}