画像の角を丸くする+縮小


こんなかんじで角を丸くしたいというかしないとほかと見た目が違ってて気持ちが悪い。

昔からイメージをいじったりするのやったことなくて苦手。

programaticにもつくれるけどサイズ固定なのでgimpでマスクを作る。
greyscaleを選んで、背景黒にして、白(255)にするとそのピクセルはマスクされない。黒だとマスクされて背景色がそのまま表示される。pngで保存。透過色とかつけたらダメ。

サンプルのTheElementsと Quartz 2D Programming Guide あたり(そんなのわかりきってるけど...)。

	float height = 36.0;
	int x = img.bounds.size.width;
	int y = img.bounds.size.height;
	CGContextRef mainViewContentContext=MyCreateBitmapContext(x,y);
	
	UIImage* driftimage = 	[UIImage imageNamed:@"drift.jpg"];

	float ratio = (float)height / 75.0;
	CGContextScaleCTM(mainViewContentContext, ratio, ratio);
	CGRect myContextRect= CGRectMake(0,0,75, 75);
    CGContextDrawImage (mainViewContentContext, myContextRect, driftimage.CGImage);// 6
	CGImageRef mainViewContentBitmapContext=CGBitmapContextCreateImage(mainViewContentContext);
	CGContextRelease(mainViewContentContext);
	UIImage* mask = [UIImage imageNamed:[NSString stringWithFormat:@"flickriconmask%d.png" , (int)height]];
	CGImageRef reflectionImage=CGImageCreateWithMask(mainViewContentBitmapContext,mask.CGImage);
	CGImageRelease(mainViewContentBitmapContext);
	UIImage *theImage=[UIImage imageWithCGImage:reflectionImage];
	CGImageRelease(reflectionImage);
	img.image  = theImage;

ふつうにimageNamedで作ったUIImageのUIImage.CGDataからもってきたやつでwithMaskでつくるとなぜーか背景が黒くなったりしてだめだった(とおもう違ったらショックー)。