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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何按比例縮小UIImage并使其酥脆/清晰而不是模糊?

如何按比例縮小UIImage并使其酥脆/清晰而不是模糊?

iOS
回首憶惘然 2019-10-24 14:19:59
我需要按比例縮小圖像,但要采用清晰的方式。例如,在Photoshop中,圖像尺寸縮小選項(xiàng)為“ Bicubic Smoother”(模糊)和“ Bicubic Sharper”。該圖像縮小算法是在某個(gè)地方開(kāi)源或記錄的,還是SDK提供了執(zhí)行此操作的方法?
查看完整描述

3 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

如果有人正在尋找Swift版本,這是@Dan Rosenstark接受的答案的Swift版本:


func resizeImage(image: UIImage, newHeight: CGFloat) -> UIImage {

    let scale = newHeight / image.size.height

    let newWidth = image.size.width * scale

    UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight))

    image.drawInRect(CGRectMake(0, 0, newWidth, newHeight))

    let newImage = UIGraphicsGetImageFromCurrentImageContext()

    UIGraphicsEndImageContext()


    return newImage

}


查看完整回答
反對(duì) 回復(fù) 2019-10-24
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

對(duì)于那些使用Swift的人,這是Swift中公認(rèn)的答案:


func resizeImage(image: UIImage, newSize: CGSize) -> (UIImage) {

    let newRect = CGRectIntegral(CGRectMake(0,0, newSize.width, newSize.height))

    let imageRef = image.CGImage


    UIGraphicsBeginImageContextWithOptions(newSize, false, 0)

    let context = UIGraphicsGetCurrentContext()


    // Set the quality level to use when rescaling

    CGContextSetInterpolationQuality(context, kCGInterpolationHigh)

    let flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height)


    CGContextConcatCTM(context, flipVertical)

    // Draw into the context; this scales the image

    CGContextDrawImage(context, newRect, imageRef)


    let newImageRef = CGBitmapContextCreateImage(context) as CGImage

    let newImage = UIImage(CGImage: newImageRef)


    // Get the resized image from the context and a UIImage

    UIGraphicsEndImageContext()


    return newImage

}


查看完整回答
反對(duì) 回復(fù) 2019-10-24
  • 3 回答
  • 0 關(guān)注
  • 669 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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