内存高效的Andr​​oid JPEG转换 [英] memory efficient android jpeg conversion

查看:130
本文介绍了内存高效的Andr​​oid JPEG转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code是如下:

    public static byte[] compress(byte[] data, CompressFormat format, int quality)
    {       
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final Bitmap bm = BitmapFactory.decodeByteArray(data, 0, data.length);
        try {
            bm.compress(format, quality, baos);
        } finally {
            bm.recycle();
        }
        return baos.toByteArray();
    }

我很担心内存使用情况,当原始图像的尺寸较大。 COM preSS()被调用,但之前再循环()被调用以下之后是现存的存储:

I'm concerned about memory usage when the size of the original image is large. After compress() is called but before recycle() is called the following are extant in memory:


  1. 原uncom pressed二进制数据(数据)。

  2. 的去codeD位图(BM)及其所有的像素数据。

  3. 在COM pressed二进制数据(BAOS内的内部存储)。

是否有基础的Andr​​oid,可能不会造成中间位图对象执行此解码/编码步骤的功能?还是我担心不必要的?

Is there any functionality in base Android that could perform this decoding/encoding step without creating the intermediate Bitmap object? Or am I worrying unnecessarily?

推荐答案

您没有选择,只能加载位图,我认为。但是,这不是一个问题。如果你的形象是巨大的,加载到内存之前​​,规模下来。

You don't have a choice but to load the Bitmap I think. But it's not a problem. If your image is huge, scale it down before loading it into memory.

看一看 http://developer.android.com/培训/显示的位图/负载bitmap.html

这篇关于内存高效的Andr​​oid JPEG转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆