中移動的觸摸我正在使用混合模式目的地刪除圖像。我成功地做到了。如何重新繪製一個已刪除的圖像與iPhone
其實我減少了觸摸的阿爾法,所以我也能夠設置實力。
現在我的問題是關於重新繪製圖像的擦除部分與觸摸(即我想用力量拉回圖像或想設置alpha更暗)。爲此,我對原始圖像進行備份,然後裁剪觸摸部分並將其與圖像合併。但問題是,它正在繪製超過它應該。
請注意,繪製重疊(需要設置上限)時,重繪過程只會使圖像變暗得比原始圖像更多。那麼,如何避免在已經繪製圖像的位置重新繪製圖像,以避免原始圖像變暗。
我也附上了代碼。
// Code to erase an image
UIGraphicsBeginImageContext(self._overlayImage.image.size);
CGRect rect =CGRectMake(0, 0, self._overlayImage.image.size.width, self._overlayImage.image.size.height) ;
CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef imageRef=self._overlayImage.image.CGImage;
if (imageRef) {
// Restore the screen that was previously saved
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, imageRef);
//CGImageRelease(imageRef);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
}
// Erase the background -- raise the alpha to clear more away with eash swipe
// [[UIImage imageNamed:@"eraser222.png"] drawAtPoint:point blendMode:kCGBlendModeDestinationOut alpha:.2];
[ [UIImage imageNamed:@"eraser222.png"] drawInRect:CGRectMake(newPoint.x-self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, newPoint.y-self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height, self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height) blendMode:kCGBlendModeDestinationOut alpha:strength/3];
self._overlayImage.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// code to draw an image
UIImage *cropped = [self imageByCropping:self.imgOrignal toRect:CGRectMake(newPoint.x-self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, newPoint.y-self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height, self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height)];
UIGraphicsBeginImageContext(self._overlayImage.image.size);
CGRect rect =CGRectMake(0, 0, self._overlayImage.image.size.width, self._overlayImage.image.size.height) ;
CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef imageRef=self._overlayImage.image.CGImage;
if (imageRef) {
// Restore the screen that was previously saved
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, imageRef);
//CGImageRelease(imageRef);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
}
[ cropped drawInRect:CGRectMake(newPoint.x-self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, newPoint.y-self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height, self.imgOrignal.size.width*2*radius/self._overlayImage.bounds.size.width, self.imgOrignal.size.height*2*radius/self._overlayImage.bounds.size.height) blendMode:kCGBlendModeNormal alpha:strength];
cropped= [UIImage imageWithData:UIImagePNGRepresentation(cropped)];
UIImage *finalimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self._overlayImage.image=finalimage;