2015-04-21 46 views
2

我正在開發一款Android應用程序,使用維納濾鏡消除圖像模糊。一旦我用輸入圖像(模糊圖像)完成了必要的計算,然後我需要爲RGBA創建一個新的未混淆的圖像,並創建新的值。我已經用Java成功編寫了這個代碼,但是找不到解決方案,我無法在Android中創建圖像。我知道你必須在Android中使用Bitmaps,但無法使用BufferedImage/Raster/WritableRaster找到setSample()方法。我在Java代碼如下所示,Android中raster.setSample()的等效函數是什麼?

final BufferedImage unblurredImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 
    final WritableRaster unblurredRaster = unblurredImage.getRaster(); 
    for (int y = 0; y < height; y++) { 
     for (int x = 0; x < width; x++) { 
      unblurredRaster.setSample(x, y, 0, (rgb[x + y * width] >> 16) & 0xFF); // red 
      unblurredRaster.setSample(x, y, 1, (rgb[x + y * width] >> 8) & 0xFF); // green 
      unblurredRaster.setSample(x, y, 2, rgb[x + y * width] & 0xFF); // blue 
      unblurredRaster.setSample(x, y, 3, (rgb[x + y*width] >> 24) & 0xFF); // alpha 
     } 
    } 

    return unblurredImage; 

回答

0

有一些選項,全部採用Bitmap類:

  • setPixel(x, y, color)其中color是打包INT ARGB格式
  • setPixels(pixels, offset, stride, x, y, width, height)其中pixels是打包int ARGB格式。
  • copyPixelsFromBuffer(buffer)

最後一個/從包裝INT ARGB格式(ARGB_8888),所以它可能是最接近你到Raster.setSample()不轉換。

+0

感謝您的回覆。我已經實現了設置像素,但現在當我測試它時,我似乎得到了內存泄漏。我搜索了這個問題,內存泄漏似乎是Android上Bitmaps的常見問題。你知道處理位圖內存泄漏的一切嗎? – skelto

+0

我不明白爲什麼這會導致內存泄漏。如果您遇到內存泄漏,我建議您提出一個新問題,並添加相關的代碼和資源。 – haraldK

相關問題