Android 在运行时反转位图

发布于 2024-12-03 16:24:07 字数 1277 浏览 0 评论 0 原文

我正在尝试使用 Paint ColorFilter 反转位图 我使用此链接作为参考: http://www.mail-archive.com/[email protected]/msg47520.html

但它绝对没有效果 - 绘制位图通常你能告诉我我做错了什么吗?

定义浮点数组:

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

在构造函数中设置绘制

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

在 Draw() 方法中

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

引用编辑:我能够通过在绘制语句中进行绘制分配来使其工作:

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

但现在它渲染速度非常慢(可能是因为它每次都会设置一个复杂的矩阵)单帧)...当它采用相同的方法时,它工作有什么原因吗?

编辑2: 没关系!!!哈哈,问题是我有两个构造函数,而我只在其中一个构造函数中配置颜色滤镜...该过程仍然非常占用 CPU 资源,并会导致帧速率问题

I am trying to invert a bitmap by using a Paint ColorFilter
I used this link as a reference:
http://www.mail-archive.com/[email protected]/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 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪痕残 2024-12-10 16:24:07

这是一个旧线程。

然而:矩阵不适合透明抗锯齿图像的反转。

应该是:

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

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
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文