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

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

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

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

iOS
胡子哥哥 2019-12-10 13:08:25
我需要按比例縮小圖像,但要采用清晰的方式。例如,在Photoshop中,圖像尺寸縮小選項為“ Bicubic Smoother”(模糊)和“ Bicubic Sharper”。該圖像縮小算法是在某個地方開源或記錄的,還是SDK提供了執(zhí)行此操作的方法?
查看完整描述

3 回答

?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

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

}



查看完整回答
反對 回復 2019-12-11
?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

對于那些使用Swift的人,這是Swift中公認的答案:


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

}



查看完整回答
反對 回復 2019-12-11
  • 3 回答
  • 0 關注
  • 562 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號