0
我有一個區域,用戶可以將其簽名添加到應用程序以驗證訂單。
他們用他們的觸摸標誌。
唯一的問題是,簽名的框架很大,如果用戶要使簽名非常小,當我保存圖像時,我會在圖像周圍留下大量空白空間,當我把它添加到進一步的電子郵件過程看起來很可怕。UIGraphicsGetImageFromCurrentImageContext裁剪到內容而不是包圍盒
有沒有什麼辦法,使用我可以將圖像裁剪到任何實際內容的邊界,而不是框的邊界本身?
我會想象這個過程會涉及到某種方式檢測空間內的內容並繪製一個CGRect來匹配它的邊界,然後再將這個CGRect傳遞迴上下文?但我不確定如何以任何形式或形式去做這件事,這是我第一次使用CGContext和圖形框架。
這裏是我的簽名繪圖代碼:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:signView];
//Define Properties
[drawView.image drawInRect:CGRectMake(0, 0, drawView.frame.size.width, drawView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineJoin(UIGraphicsGetCurrentContext(), kCGLineJoinBevel);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), true);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), true);
//Start Path
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
//Save Path to Image
drawView.image = UIGraphicsGetImageFromCurrentImageContext();
lastPoint = currentPoint;
}
感謝您的幫助,如果你可以提供它。