2012-01-31 72 views
1

我要通過機器人去改變它作爲在Java我有改變位圖圖像的像素陣列

byte[] pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); 

(這裏圖像是BufferedImage的),但

int[] pixels; 
image.getPixels(pixels, 0, width, 0, 0, width , height); 

(這裏imgae是位圖圖像) 不像java那樣返回像素值。

+2

INT寬度= bitmap.getWidth(); int height = bitmap.getHeight(); int [] pixels = new int [width * height]; bitmap.getPixels(像素,0,寬度,0,0,寬度,高度); //試試這個 – 2012-01-31 12:37:25

+0

使用Hiren dabhi lines.It也可以在android上工作。+ 1僱用n – Sameer 2012-01-31 12:58:20

+0

這個已經解決了這樣的問題 \t \t int [] pix1 = new int [w * h]; \t \t image.getPixels(pix1,0,w,0,0,w,h); \t \t pixels = new byte [pix1.length * 3]; \t \t for(int i = 0; i > 0)&0xFF); \t \t \t像素[Tind的++] =(字節)((TD >> 8)爲0xFF); \t \t \t pixels [tind ++] =(byte)((td >> 16)&0xFF); \t \t \t \t \t} – shailesh 2012-02-03 08:08:15

回答

0

嘗試這樣,

Bitmap bmp = intent.getExtras().get("data"); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 
+0

這結果將被壓縮,他要求對應於標準的Java #getPixels(..)的方法。 – Jens 2012-01-31 12:54:44