2010-07-19 41 views
2

如何用Inputstream打開位圖?用Inputstream打開位圖

例如InputStream inputStream = image其中圖像的類型是Bitmap

謝謝。

+0

「形象的類型是位圖」是什麼意思?那是一個java類名,還是你指的是BMP格式?輸入流僅用於讀取一系列字節。你想加載一個文件,就像是或解碼? – leonbloy 2010-07-19 11:02:54

回答

3

要在您的應用程序讀取的位圖圖像,
BufferedImage img = ImageIO.load("mybitmap.bmp");

要從緩衝的圖像對象獲取的像素,使用getRGB()

int[] pixels = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth()); 

的javadoc getRGB()。請參閱this文章。

2
InputStream is = new BufferedInputStream(new FileInputStream("source.bmp")); 

這是你所需要的?

2
  if (thumbnail != null) { 
       ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       thumbnail.compress(Bitmap.CompressFormat.PNG, 100, baos); 
       inputstream = new ByteArrayInputStream(baos .toByteArray()); 
      } 

試試這個