gpt4 book ai didi

android - Android 中的位图 channel 顺序不同

转载 作者:行者123 更新时间:2023-11-30 03:31:55 25 4
gpt4 key购买 nike

我在 Android 中遇到了 Air Native Extension 的问题。

ANE 从 Actionscript 端接收一个位图,将其压缩为 jpeg 格式并将其发送回将其写入存储的 Actionscript。

一切都很好,但最后一件事。

似乎 Actionscript 的 channel 顺序与 Android 中的不同,所以我的压缩图像用红色代替蓝色。这是代码:

Actionscript(我正在使用一个名为 deng.fzip.FZipLibrary 的库从 zip 包中获取位图)

__image = __fl.getBitmapData(path);
__de = new DataExchange();
__ba = __de.bitmapEncode(__image) as ByteArray;

安卓

...
try {
inputValue = (FREBitmapData)arg1[0];
inputValue.acquire();
int srcWidth = inputValue.getWidth();
int srcHeight = inputValue.getHeight();
Bitmap bm = Bitmap.createBitmap(srcWidth, srcHeight, Config.ARGB_8888);
bm.copyPixelsFromBuffer(inputValue.getBits());
ByteArrayOutputStream os = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 80, os);
compressed = os.toByteArray();
inputValue.release();
} catch (Exception e) {
e.printStackTrace();
}

try {
returnValue = FREByteArray.newByteArray();
returnValue.setProperty("length", FREObject.newObject(compressed.length));
returnValue.acquire();
ByteBuffer returnBytes = returnValue.getBytes();
returnBytes.put(compressed, 0, compressed.length);
returnValue.release();
}
...

有人知道如何在发回图像之前在 android 端将红色转换为蓝色吗?还是需要在 actionscript 端完成?

非常感谢和问候,

詹皮耶罗

最佳答案

你可以这样切换颜色:

(这段代码不是我的,不幸的是我忘记了我是在哪里找到它的,所以信用在其他地方)

private Bitmap m_encodingBitmap         = null;
private Canvas m_canvas = null;
private Paint m_paint = null;
private final float[] m_bgrToRgbColorTransform =
{
0, 0, 1f, 0, 0,
0, 1f, 0, 0, 0,
1f, 0, 0, 0, 0,
0, 0, 0, 1f, 0
};
private final ColorMatrix m_colorMatrix = new ColorMatrix(m_bgrToRgbColorTransform);
private final ColorMatrixColorFilter m_colorFilter = new ColorMatrixColorFilter(m_colorMatrix);

...

try{

FREBitmapData as3Bitmap = (FREBitmapData)args[0];
as3Bitmap.acquire();
m_encodingBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
m_canvas = new Canvas(m_encodingBitmap);
m_paint = new Paint();
m_paint.setColorFilter(m_colorFilter);

m_encodingBitmap.copyPixelsFromBuffer(as3BitmapBytes);
as3Bitmap.release();
//
// Convert the bitmap from BGRA to RGBA.
//
m_canvas.drawBitmap(m_encodingBitmap, 0, 0, m_paint);

...

希望对您有所帮助...Timm

关于android - Android 中的位图 channel 顺序不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17314467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com