简体   繁体   English

Android在运行时反转位图

[英]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 我试图通过使用Paint ColorFilter来反转位图我使用此链接作为参考: 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 在构造函数中设置Paint

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

Reference in Draw() method Draw()方法中的引用

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

EDIT: I was able to get it to work by having the paint assignment in the draw statement: 编辑:我能够通过在draw语句中进行绘制赋值来使其工作:

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!!! 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 大声笑,问题是我有两个构造函数,我只在其中一个配置colorfilter ...进程仍然是CPU密集型并导致帧率问题

This is an old thread. 这是一种旧思路。

However: The Matrix is not good for inversion of anti-aliased images with transparency. 但是:Matrix不适用于具有透明度的抗锯齿图像的反转。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM