第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在視網(wǎng)膜顯示質(zhì)量不變的情況下捕捉UIView到UI圖像

如何在視網(wǎng)膜顯示質(zhì)量不變的情況下捕捉UIView到UI圖像

慕俠2389804 2019-06-14 17:16:31
如何在視網(wǎng)膜顯示質(zhì)量不變的情況下捕捉UIView到UI圖像我的代碼適用于正常設(shè)備,但在視網(wǎng)膜設(shè)備上創(chuàng)建模糊圖像。有人知道解決我的問題嗎?+ (UIImage *) imageWithView:(UIView *)view{     UIGraphicsBeginImageContext(view.bounds.size);     [view.layer renderInContext:UIGraphicsGetCurrentContext()];     UIImage * img = UIGraphicsGetImageFromCurrentImageContext();     UIGraphicsEndImageContext();     return img;}
查看完整描述

3 回答

?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個贊


不使用UIGraphicsBeginImageContextUIGraphicsBeginImageContextWithOptions(如文件所示)在這頁上)。為Scale傳遞0.0(第三個參數(shù)),您將得到一個與屏幕的縮放因子相等的上下文。

UIGraphicsBeginImageContext使用的固定比例因子為1.0,因此在iPhone 4上的圖像實(shí)際上與其他iPhone上的圖像完全相同。我敢打賭,無論是iPhone 4在你隱式放大的時(shí)候應(yīng)用了一個過濾器,還是你的大腦對它的感覺比它周圍的一切都不那么清晰。

所以,我猜:

#import <QuartzCore/QuartzCore.h>+ (UIImage *)imageWithView:(UIView *)view{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;}

在SWIFT 4中:

func image(with view: UIView) -> UIImage? {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0.0)
    defer { UIGraphicsEndImageContext() }
    if let context = UIGraphicsGetCurrentContext() {
        view.layer.render(in: context)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        return image    }
    return nil}


查看完整回答
反對 回復(fù) 2019-06-14
?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個贊

我創(chuàng)建了一個基于@Dima解決方案的SWIFT擴(kuò)展:

extension UIImage {
    class func imageWithView(view: UIView) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0)
        view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img    }}

編輯:SWIFT 4改進(jìn)版

extension UIImage {
    class func imageWithView(_ view: UIView) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0)
        defer { UIGraphicsEndImageContext() }
        view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
        return UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()
    }}

用法:

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))  let image = UIImage.imageWithView(view)


查看完整回答
反對 回復(fù) 2019-06-14
  • 3 回答
  • 0 關(guān)注
  • 763 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號