久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 UIView/UIScrollView 創(chuàng)建圖像

How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創(chuàng)建圖像)
本文介紹了如何從 UIView/UIScrollView 創(chuàng)建圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 UIScrollView 中有一張圖片,可以滾動和縮放.

I have an image in an UIScrollView, that can be scrolled and zoomed.

當用戶按下按鈕時,我希望代碼從我用 CGRect 指定的區(qū)域內的 UIScrollView 的任何部分創(chuàng)建圖像.

When the user presses a button, I want the code to create an image from whatever part of the UIScrollView is inside an area I specify with a CGRect.

我見過裁剪 UIImages 的代碼,但我無法調整它來為視圖做同樣的事情,因為它使用 CGContextDrawImage.

I've seen code to crop UIImages, but I can't adapt it to do the same for a view, because it uses CGContextDrawImage.

有什么想法嗎?

干杯,安德烈

推薦答案

我已經(jīng)搞定了.

這是我的解決方案,基于網(wǎng)絡上的幾個不同的解決方案:

Here's my solution, based on a few different ones from the web:

- (UIImage *)imageByCropping:(UIScrollView *)imageToCrop toRect:(CGRect)rect
{
    CGSize pageSize = rect.size;
    UIGraphicsBeginImageContext(pageSize);

    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(resizedContext, -imageToCrop.contentOffset.x, -imageToCrop.contentOffset.y);
    [imageToCrop.layer renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;
}

您使用以下方式調用:

CGRect clippedRect = CGRectMake(0, 0, 320, 300);
picture.image = [self imageByCropping:myScrollView toRect:clippedRect];

這篇關于如何從 UIView/UIScrollView 創(chuàng)建圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
How to auto scroll UIScrollView using timer?(如何使用計時器自動滾動 UIScrollView?)
Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources(以編程方式強制 UIScrollView 停止?jié)L動,以便與多個數(shù)據(jù)源共享表格視圖) - IT屋-程序員軟件開發(fā)技術分享
Xcode amp; Swift - Detecting user touch of UIView inside of UIScrollView(Xcode amp;Swift - 在 UIScrollView 內檢測 UIView 的用戶觸摸)
What does contentOffset do in a UIScrollView?(UIScrollView 中的 contentOffset 有什么作用?)
主站蜘蛛池模板: 国产乱码精品一区二区三区中文 | 91精品国产91久久久久久三级 | 亚洲国产一区二区三区在线观看 | 国产欧美精品区一区二区三区 | 精品国产乱码久久久久久影片 | 观看av| 亚洲久久在线 | 久久免费国产视频 | 精品国产乱码久久久 | a免费视频 | 中文天堂在线观看 | 中文字幕一区在线观看视频 | 国产日产精品一区二区三区四区 | 欧美精品1区 | 亚洲国产成人av | 欧美精品一区二区三区在线播放 | 黄片毛片免费观看 | 久久a久久| www久| 国产精品久久亚洲7777 | 久久99久久99| 亚洲精品免费观看 | wwwww在线观看 | 高清国产一区二区 | 一级做a| 国产精品美女久久久久 | 蜜桃毛片 | 日韩精品一区二区三区视频播放 | 国内91在线 | 亚洲精品久久国产高清情趣图文 | 亚洲精品国产综合区久久久久久久 | 日韩欧美中文字幕在线观看 | 国产伦精品一区二区三区照片91 | 日本精品久久 | 天天干干 | 久久精品中文 | 欧美日韩1区2区 | 国产精品美女久久久久久久网站 | 日本亚洲一区 | 伊人一区 | 久久精品国产久精国产 |