I draw on the image. And save this image in the camera frame, when I save this image, then the alpha image will not be set properly. if I draw an image with 80% alpha, and then click save image, you will save 40% (approximate) alpha. I do not use lib for this. I draw with touch.


code
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; currentPoint = [touch locationInView:self.tempimage]; UIGraphicsBeginImageContext(self.tempimage.frame.size); [tempimage.image drawInRect:CGRectMake(0, 0, self.tempimage.frame.size.width, self.tempimage.frame.size.height)]; CGContextMoveToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); strpoint=NSStringFromCGPoint(currentPoint); strpoint1=NSStringFromCGPoint(lastPoint); CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextRef context = UIGraphicsGetCurrentContext(); if ([linewidth isEqualToString:@"40"]) { CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 40.0); lineWidth=40.0; } if ([linewidth isEqualToString:@"30"]) { CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0); lineWidth=15.0; } if ([linewidth isEqualToString:@"20"]) { CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); lineWidth=5.0; } if ([streraser isEqualToString:@"eraser"]) { CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidth); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); }
}
- (IBAction)btnsave:(id)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:Save_Folder_Name,@"Cancel", nil]; [actionSheet showInView:self.view]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { UIGraphicsBeginImageContextWithOptions(self.tempimage.bounds.size, NO, 0.0); // [self.tempimage.image drawInRect:CGRectMake(0, 0, self.tempimage.frame.size.width, self.tempimage.frame.size.height)]; [self.tempimage.image drawInRect:CGRectMake(0, 0, tempimage.frame.size.width, tempimage.frame.size.height) blendMode:blendmode alpha:lineAlpha]; UIImage *SaveImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(SaveImage, self,@selector(image:didFinishSavingWithError:contextInfo:), nil); } } - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { // Was there an error? if (error != NULL) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Image could not be saved.Please try again" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Close", nil]; [alert show]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Image was successfully saved in photoalbum" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Close", nil]; [alert show]; } }
Any help would be appreciated.