2012-09-22 61 views
-2

在java中...我有RGB像素的一個整數數組,意味着我的節目的輸出如下: '創建圖像值

 
Pixel 1: 255 200 191 231 
Pixel 2: 255 237 028 036 
Pixel 3: 255 034 177 076 
Pixel 4: 255 085 140 066 
Pixel 5: 255 200 191 231 
Pixel 6: 255 237 028 036 
Pixel 7: 255 231 188 167 
Pixel 8: 255 237 028 036 
Pixel 9: 255 237 028 036 
Pixel 10: 255 063 072 204 
Pixel 11: 255 226 125 144 
Pixel 12: 255 063 072 204 
Pixel 13: 255 200 191 231 
Pixel 14: 255 062 187 099 
Pixel 15: 255 255 127 039 
Pixel 16: 255 255 127 039 
Pixel 17: 255 200 191 231 
Pixel 18: 255 212 177 189 
Pixel 19: 255 063 072 204 
Pixel 20: 255 040 158 100 
Pixel 21: 255 034 177 076 
Pixel 22: 255 237 028 036 
Pixel 23: 255 248 253 249 
Pixel 24: 255 165 169 231 
Pixel 25: 255 200 191 231 

如何創建尺寸5的圖像使用上述數據的x 5圖像...?'

+5

此問題已由原始海報交叉發佈到互聯網上的許多網站和論壇。原始海報:你被要求讓所有網站知道交叉帖子,但你仍然拒絕遵循這個基本的禮貌。爲什麼? –

+0

你得到這些數據作爲字節數組或字符串逐行或以某種方式? –

+0

將RGB值放入整數數組中,放在i%3部分中。創建BufferedImage和WritableRaster的實例,將buffimage柵格分配給新創建的實例。設置光柵像素,基本完成。 – nullpotent

回答

1

創建BufferedImage 得到Graphics/Graphics2D對象從BufferedImage的 和繪畫與Graphics對象的像素。

的BufferedImage中可以存儲爲ImageIO文件或顯示在自己的Component/JComponent

有點僞碼

BufferedImage bi = new BufferedImage(5,5,BufferedImage.TYPE_INT_ARGB); 
Graphics2D g = (Graphics2D) bi.getGraphics(); 
while(i < 25){ 
    g.setColor(new Color(See Api for more details on how to create a Color); 
    g.drawRect(i/5, i%5, 1,1); 
} 

現在你有一個BufferdImage被保存的ImageIO

ImageIO.write(bi, "png", new File(output)); 

或者獲取一個新的JComponent並覆蓋它的paint方法。這項任務有很多資源。

+0

@daniel ...'你能用代碼解釋嗎?' – KungFuPanda

+0

Thanx ...幫助' – KungFuPanda