簡體   English   中英

UIImageView:旋轉和縮放。 如何保存結果?

[英]UIImageView: Rotated and Scaled. How do I save the results?

我正在嘗試將旋轉和縮放的UIImageView保存為UIImage的位置以及用戶也編輯過的縮放比例。 但是我只能設法保存原始圖像,然后再進行編輯。 如何以相同的縮放和旋轉方式保存UIImageView中顯示的圖像? 我已經讀過我需要使用UIGraphicsGetCurrentContext(),但是我保存了相同的原始圖像(但是被翻轉了),而不是旋轉的圖像! 建議和提示將非常有幫助。 先感謝您。

(UIImage *)getImage
{
CGSize size = CGSizeMake(250, 250);
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();

// Add circle to path
CGPathAddEllipseInRect(path, NULL, CGRectMake(0, 0, 250, 250));
CGContextAddPath(context, path);

// ****************** touchImageView is my UIImageView ****************//
CGContextDrawImage(context, CGRectMake(0, 0, 250, 250), [touchImageView image].CGImage);

UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();

// Clip to the circle and draw the logo
CGContextClip(context);
UIGraphicsEndImageContext();

return scaledImage;

}

基於視圖的變換將應用上下文的輸出,而不是上下文本身。 我相信您必須使用鏈接文本核心圖形的特定功能來縮放和旋轉圖像上下文本身。

(我可能是錯的。我不記得我過去做得怎么樣了。把它和一粒鹽一起吃。)

我在您發布的代碼中看不到會旋轉圖像的任何內容。 您忘記添加了嗎?

看來您在正確的軌道上。 現在,您應該使用轉換例程CGContextScaleCTMCGContextRotateCTM適當地修改您的轉換矩陣,然后(避免翻轉),使用-[UIImage drawAtPoint:]繪制UIImage而不是使用CGContextDrawImage

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM