Custom Drawing of Alpha Images

泪湿孤枕 提交于 2019-12-13 15:23:58

问题


I am trying to do custom drawing of an image(with alpha) and eventually going to apply different color tints to it. Right now I am just trying to draw it correctly. This might be simple problem but the result is the ALPHA on my image is black. Image is .png created from photoshop with correct alpha.

- (void) drawRect:(CGRect)area
{

[imgView.image drawInRect: area blendMode:blendMode alpha:alpha]; // draw image
}

blendMode is normal and alpha is 1.0. The image is good except alpha being black. Any help appreciated.

Tried another method of drawing, but shows black alpha and upside down(don't care about it being upside right now tho)

- (void) drawRect:(CGRect)area
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);

// Draw picture first
CGContextDrawImage(context, area, imgView.image.CGImage);

CGContextRestoreGState(context);
}

回答1:


[imagename drawInRect:CGRectMake(x, y, width, height)];

or

[imagename drawAtPoint:CGPointMake(x, y)];



回答2:


I believe that when you use drawInRect:blendMode:alpha, the alpha that you pass in overrides the alpha in your image. The documentation I just looked at wasn't quite clear.



来源:https://stackoverflow.com/questions/1478761/custom-drawing-of-alpha-images

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