0
我正在製作一個應用程序,用戶在其中選擇圖像,通過縮放(在uiscrollview中)並在視圖中移動它來調整它的大小。完成後,我想保存圖像,就像我們可以在uiscrollview中看到的一樣。你有什麼主意嗎 ?如何「裁剪」一個uiimage?
謝謝。
我正在製作一個應用程序,用戶在其中選擇圖像,通過縮放(在uiscrollview中)並在視圖中移動它來調整它的大小。完成後,我想保存圖像,就像我們可以在uiscrollview中看到的一樣。你有什麼主意嗎 ?如何「裁剪」一個uiimage?
謝謝。
下面是代碼......
這裏frontGround是一個imageview的並且 testScrool是滾動視圖
希望這會爲你工作。
UIGraphicsBeginImageContext(testScrool.frame.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect clippedRect = CGRectMake(0, 0, testScrool.frame.size.width, testScrool.frame.size.height);
CGContextClipToRect(currentContext, clippedRect);
CGRect drawRect = CGRectMake(testScrool.frame.origin.x * -1,
testScrool.frame.origin.y * -1,frontGround.frame.size.width, frontGround.frame.size.height);
CGContextDrawImage(currentContext, drawRect, frontGround.image.CGImage);
UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
frontGround.image = cropped;