2010-04-05 166 views
0

我正在開發一款應用程序,我需要將iphone屏幕截圖的一部分保存爲JPEG格式,然後通過電子郵件發送。屏幕的部分有一些文字標籤,字段等任何想法。請我怎麼能節省屏幕爲JPEG(因此,我任何幫助/示例代碼是高度讚賞新手)如何將iphone屏幕截圖保存爲jpeg圖像?

回答

4

下面的代碼將一個視圖中的內容保存到用戶的照片庫。您應該可以修改它以便能夠通過電子郵件發送文件。

CGRect myRect = [myView bounds]; 
    UIGraphicsBeginImageContext(myRect.size); 

    CGContextRef ctx = UIGraphicsGetCurrentContext(); 
    [[UIColor blackColor] set]; 
    CGContextFillRect(ctx, myRect); 

    [myView.layer renderInContext:ctx]; 

    UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext(); 

    // Replace the following line with code that emails the image 
    UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil); 
    UIGraphicsEndImageContext(); 
0

http://blogs.zdnet.com/mobile-gadgeteer/?p=1278的一部分:

當您在想要捕捉的屏幕上時,按住主頁按鈕,然後按電源/睡眠按鈕。然後,您的屏幕截圖將在您的iPhone上出現照片庫,您可以根據需要將其發送或同步。

+0

問題是想在代碼中這樣做。 – MystikSpiral 2010-04-05 17:07:05

+0

的確,我正在尋找一個編碼解決方案。儘管如此,謝謝你的回覆。 – Ali 2010-04-06 05:57:32