自定义Alpha图片的绘制 [英] Custom Drawing of Alpha Images

查看:105
本文介绍了自定义Alpha图片的绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对图像(带有Alpha)进行自定义绘制,最终将对其应用不同的颜色。现在,我只是试图正确绘制它。这可能是简单的问题,但结果是我图像上的ALPHA是黑色的。

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是正常的,alpha是1.0。图像很好,除了alpha为黑色。

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

尝试了另一种绘制方法,但是显示黑色alpha字母且倒置(不必担心它现在是否正上方)

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);
}


推荐答案

我相信当您使用 drawInRect:blendMode:alpha ,您传入的Alpha会覆盖图像中的Alpha。我刚刚看过的文档不太清楚。

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.

这篇关于自定义Alpha图片的绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆