+(uiimage*)imagebyscalingandcroppingforsize:(uiimage*)selectedimage withtargetsize:(cgsize)size
// else
// // uigraphicsbeginimagecontext(size);
// [selectedimage drawinrect:cgrectmake(0, 0, size.width, size.height) blendmode:kcgblendmodeplusdarker alpha:1];
// // uiimage *scaledimage = uigraphicsgetimagefromcurrentimagecontext();
// uigraphicsendimagecontext();
// return scaledimage;
uiimage *newimage = nil;
cgsize imagesize = selectedimage.size;
cgfloat width = imagesize.width;
cgfloat height = imagesize.height;
cgfloat targetwidth = size.width;
cgfloat targetheight = size.height;
cgfloat scalefactor = 0.0;
cgfloat scaledwidth = targetwidth;
cgfloat scaledheight = targetheight;
cgpoint thumbnailpoint = cgpointmake(0.0,0.0);
if (cgsizeequaltosize(imagesize, size) == no)
else
if (widthfactor < heightfactor)
}
uigraphicsbeginimagecontext(size); // this will crop
cgrect thumbnailrect = cgrectzero;
thumbnailrect.origin = thumbnailpoint;
thumbnailrect.size.width = scaledwidth;
thumbnailrect.size.height = scaledheight;
[selectedimage drawinrect:thumbnailrect];
newimage = uigraphicsgetimagefromcurrentimagecontext();
if(newimage == nil)
// nslog(@"could not scale image");
//pop the context to get back to the default
uigraphicsendimagecontext();
return newimage;
}
Android中測量Text的寬度和高度
android中,在自定義view中通過canvas繪製文字時,經常需要測量文字的寬度和高度。這裡記錄下幾種比較常用的方法,僅作備忘。paint paint new paint paint.settextsize size float strwidth paint.measuretext str p...
iOS中調整view層級位置的兩個屬性
控制項的層級關係和你加入到父檢視的順序有關,也就是先addsubview至父檢視的,層級越低,會被後加入的遮蓋。可以通過以下函式改變子檢視的層級 將乙個uiview顯示在最前面 void bringsubviewtofront uiview view 將檢視顯示在下面 void sendsubvie...
iOS中init和initialize的特點
在nsobject.h中有兩個類方法 void load void initalize initialize和load,我們並不需要在這兩個方法的實現中使用super呼叫父類的方法。load不像普通方法一樣遵守繼承規則,當自己的類沒有實現load方法時,不管超類是否實現,自己都不會載入load方法,...