She*_* Sk 3 java rgb android android-bitmap
我已通过BitmapFactory.decodeStream
以下代码将 JPEG 图像转换为 RGB 颜色值数组:
picw = selectedImage.getWidth();
pich = selectedImage.getHeight();
int[] pix = new int[picw * pich];
selectedImage.getPixels(pix, 0, picw, 0, 0, picw, pich);
int R, G, B;
for (int y = 0; y < pich; y++) {
for (int x = 0; x < picw; x++) {
int index = y * picw + x;
R = (pix[index] >> 16) & 0xff;
G = (pix[index] >> 8) & 0xff;
B = pix[index] & 0xff;
pix[index] = (R << 16) | (G << 8) | B;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如何将此数组转换回图像?
您可以使用静态方法Bitmap.createBitmap。例如
Bitmap bmp = Bitmap.createBitmap(pix, picw, pich, Bitmap.Config.ARGB_8888)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3227 次 |
最近记录: |