2010-01-07 65 views
0

如何保存拉伸的圖像?如何保存拉伸的圖像?

我有一個小的(50 X 50)圖像,我在UIImageView上顯示它時已經拉伸(通過選擇scaletofit模式。)現在我需要獲取&保存拉伸圖像。 我試圖通過使用UIImageView的圖像屬性,但它給了我原始圖像不是拉伸圖像。

那麼,你有什麼想法如何解決這個問題?如果那麼請幫助我或引導我或至少給我一個提示。

盼望您的回覆.........

感謝

回答

0

你必須通過複製視圖的CGContext上的位圖(核心圖形上下文)創建的圖像。這已經在stackoverflow之前問過,但我現在找不到答案。

0

您需要將您的UIImageView渲染到您創建的圖形上下文中:

 
 
UIGraphicsBeginImageContext(yourUIImageView.frame.size); 
yourUIImageView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

//get the PNG representation of the UIImage (but you could do the same with JPEG NSData *myData = UIImagePNGRepresentation(screenshot); //then save it to a file [myData writeToFile:thePathToWriteYourFileAsNSString atomically:YES];