如何将图像附加在一起?

时间:2015-02-06 03:16:15

标签: java android image-processing bitmap out-of-memory

我有一个项目需要在大图像上应用图像过滤器。为了避免OutOfMemoryExceptions,我将原始图像拆分为较小的部分(图块),然后在较小的图块上应用滤镜。

但是,我似乎无法将图块组合在一起以创建与原始尺寸相同的受控图像。

我无法在画布上绘图,因为尺寸太大而且会导致OutOfMemoryExceptions。

到目前为止,我尝试了以下代码:

try {
    OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
    ByteArrayOutputStream stream = null;

    if (outputStream != null) {
        for (int i = 0; i < 4; i++) {
            stream = new ByteArrayOutputStream();
            if (bitmap != null) {
                bitmap.recycle();
            }

            bitmap = BitmapFactory.decodeFile(Directory.OCR_IMG + "test-" + i + ".jpg");
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

            byte[] byteArray = stream.toByteArray();

            outputStream.write(byteArray, 0, byteArray.length);

            stream.flush();
            stream.close();
        }
}
catch (Exception e) {
    e.printStackTrace();
}
finally {
    outputStream.close();
}

但结果图像只包含第一个图块。

任何帮助将不胜感激。谢谢!

0 个答案:

没有答案