CoreGraphics: Image Transparent Background

北战南征 提交于 2019-12-12 14:19:35

问题


I am trying to draw an image with a 2px transparent border:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0);

CGContextAddRect(context, CGRectMake(0.0, 0.0, outputImageSize.width, outputImageSize.height));
CGContextDrawPath(context, kCGPathFill);


[image drawInRect:CGRectMake(2.0,
                             ((outputImageSize.height - userPhotoImageSize.height) / 2.0) +2.0,
                             userPhotoImageSize.width -4.0, 
                             userPhotoImageSize.height -4.0)];


UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

It keeps getting black border (background)... =( Any ideas?


Solved, the uiimageview in which I set the image was simply black background =( The above code works!


回答1:


Solved, the uiimageview in which I set the image was simply black background =( The above code works!



来源:https://stackoverflow.com/questions/5593717/coregraphics-image-transparent-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!