开发者

Android Invert a Bitmap at Runtime

I am trying to invert a bitmap by using a Paint ColorFilter I used this link as a reference: http://www.mail-archive.com/android-developers@googlegroups.com/msg47520.html

but it has absolutely no effect - bitmap is drawn normally can you tell me what I'm doing incorrectly?

Define float array:

float invert [] = { 
        -1.0f,  0.0f,  0.0f,  1.0f,  0.0f, 
        0.0f,  -1.0f,  0.0f,  1.0f,  0.0f, 
        0.0f,  0.0f,  -1.0f,  1.0f,  0.0f, 
        1.0f,  1.0f,  1.0f,  1.0f,  0.0f 
}; 

Setup Paint in constructor

    ColorMatrix cm = new ColorMatrix(invert); 
    invertPaint.setColorFilter(new ColorMatrixColorFilter(cm)); 
    

Reference in Draw() method

c.drawBitmap(Bitmap, null, Screen, invertPaint);

EDIT: I was able to get it to work by having the paint assignment in the开发者_Python百科 draw statement:

ColorMatrix cm = new ColorMatrix(invert); 
invertPaint.setColorFilter(new ColorMatrixColorFilter(cm)); 
c.drawBitmap(rm.getBitmap(DefaultKey), null, Screen, invertPaint);

but now it renders really slow (probably because its setting up a complicated matrix every single frame) ...is there a reason it works when it's in the same method?

EDIT2: NEVERMIND!!! Lol, the issue was that I had two constructors and I was only configuring the colorfilter in one of them...the proccess is still very CPU intensive and causes framerate issues


This is an old thread.

However: The Matrix is not good for inversion of anti-aliased images with transparency.

Should be:

float invert[] =
{
-1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 
0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, -1.0f, 1.0f, 1.0f, 
0.0f, 0.0f, 0.0f, 1.0f, 0.0f
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜