在Java / Android中将原始图像(如DNG)转换为JPG格式的任何API或代码

时间:2014-05-27 04:19:29

标签: java android image jpeg

我希望使用Android将原始图像数据(如.DNG扩展名)转换为JPG格式。 Playstore中有一个类似的应用程序

Raw Decoder Free

任何人都可以提供一些线索或任何开源代码来做同样的事情。

[编辑]  我已经尝试使用Visual C ++ THIS并能够开发适用于Windows操作系统的应用程序。

我正在寻找Android的东西。

1 个答案:

答案 0 :(得分:1)

您可以使用原始图像中的位图。

为此,您可以将每个字节扩展到32位ARGB int。 A是alpha 0xff,R G B是像素值。 请尝试以下代码。 Source是原始图像的字节数组。

byte [] Source; //Comes from somewhere...
byte [] Bits = new byte[Source.length*4]; //That's where the ARGB array goes.
int i;
for(i=0;i<Source.length;i++)
{
    Bits[i*4] =
        Bits[i*4+1] =
        Bits[i*4+2] = ~Source[i]; //Invert the source bits
    Bits[i*4+3] = -1;//0xff, that's the alpha.
}

//Now put these nice ARGB pixels into a Bitmap object

Bitmap bm = Bitmap.createBitmap(Width, Height, Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits));

或库可用here。但是你需要使用ndk。