iOS開發之UIImage等比縮放

2021-07-04 08:26:58 字數 1085 閱讀 8072

前面講了擷取uiimage指定大小區域,很方便的擷取uiimage。今天要和大家分享的是uiimage的縮放。

兩種縮放:

縮放到指定大小,也就是指定的size.

等比縮放。

- (uiimage*)imagecompresswith******:(uiimage*)image scaledtosize:(cgsize)size

- (uiimage*)imagecompresswith******:(uiimage*)image scale:(float)scale

scale是縮放係數 。

- (uiimage*)imagebyscalingandcroppingforsize:(cgsize)targetsize

else if (widthfactor < heightfactor)

}uigraphicsbeginimagecontext(targetsize); // this will crop

cgrect thumbnailrect = cgrectzero;

thumbnailrect.origin = thumbnailpoint;

thumbnailrect.size.width= scaledwidth;

thumbnailrect.size.height = scaledheight;

[sourceimage drawinrect:thumbnailrect];

newimage = uigraphicsgetimagefromcurrentimagecontext();

if(newimage == nil)

nslog(@"could not scale image");

//pop the context to get back to the default

uigraphicsendimagecontext();

return newimage;

}

iOS開發之UIImage等比縮放

謝謝大家的支援和關愛。假設有做的不到的地方,還請海涵。畢竟我乙個人的力量是有限的。我會盡自己最大的努力大家準備一些乾貨。有些內容可能都是比較基礎的,記住 不積跬步無以至千里,不積小流無以成江海。worldligang 163.com前面講了擷取uiimage指定大小區域,非常方便的擷取uiimage...

IOS瘋狂基礎之UIImage

cgimage和cgimageref這兩個應當是用來重繪圖形的類,它們在應用時是按照影象的畫素矩陣來繪製的,它們可以用來處理bitmap。cgimageref與uiimage的互轉 cgimageref轉換成uiimage cgimageref ioffscreen cgbitmapcontextc...

iPhone開發之UIImage應用與記憶體管理

用uiimage載入影象的方法很多,最常用的是下面兩種 1 用imagenamed函式 uiimage imagenamed imagename 2 用nsdata的方式載入,例如 1.nsstring filepath nsbundle mainbundle pathforresource fil...