我想用触摸事件来模拟橡皮擦效果,以显示顶部阻挡的图像,例如灰色;
像这样的东西:

我已经找到了很长时间的解决方案,但我做不好.
以下是我的自定义视图代码:CustomView.m:
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self setup];
}
return self;
}
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
-(void)setup
{
[self setMultipleTouchEnabled:NO];
[self setBackgroundColor:[UIColor darkGrayColor]];
self.drawingPath = [UIBezierPath bezierPath];
[self.drawingPath moveToPoint:CGPointZero];
[self.drawingPath setLineWidth:5.0];
self.image = [UIImage imageNamed:@"transformers.jpg"];
self.shapeLayer = [CAShapeLayer layer];
self.caLayer = [CALayer layer];
self.caLayer.frame = self.bounds;
self.caLayer.contents = (id)(self.image.CGImage);
[self.layer addSublayer:self.caLayer];
}
- (void)drawRect:(CGRect)rect
{
self.shapeLayer.path = [self.drawingPath CGPath];
self.caLayer.mask = self.shapeLayer; …Run Code Online (Sandbox Code Playgroud) 我是Unity开发人员的首发,我在设备中保存了一个图像文件,文件路径如下所示:
string filePath = Application.persistenceDataPath + "myImage.png";
Run Code Online (Sandbox Code Playgroud)
如何将其解码为字节数组以便我可以使用它?非常感谢你!