Android不压缩即可保存位图 [英] android save bitmap without compression

查看:131
本文介绍了Android不压缩即可保存位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android.我需要保存一个位图而又不失质量.

I'm working on android. I need to save a bitmap without quality lost.

我尝试使用位图的compress()方法将质量设置为100.这对我不起作用,因为位图失去了太多的质量.我已经测试了JPEG和PNG格式.

I have tried it using compress() method of Bitmap, setting quality to 100. This not works for me, the bitmap loses too much quality. I have tested with JPEG and PNG formats.

我已经测试过将位图复制到ByteBuffer,然后提取byte[]并使用FileOutputStream保存它.在这种情况下,我将无法显示以这种方式保存的图像,只能看到空白页面.

I have tested to copy the bitmap to a ByteBuffer, then extract the byte[] and saving it using a FileOutputStream. In this case, I can't display images saved using this way, I only see a blank page.

我的问题是,有没有办法在不压缩的情况下将位图保存到SD卡中?

My question is, is there any way to save a bitmap in SD card without compression?

这是我的部分代码

public class MainActivity extends ActionBarActivity {

    [...]

    @Override
    protected void onActivityResult(int reqCode, int resCode, Intent handler){
        super.onActivityResult(reqCode, resCode, handler);
        if(reqCode == CAPTURE_IDENTIFIER && resCode == Activity.RESULT_OK){
// THis is that I have tested.
//          Object o = handler.getData();
//          Object o2 = handler.getExtras().getParcelable("data");
//          Object o3 = handler.getExtras().get("data");
//          Object o4 = handler.getParcelableExtra("data");
//          
            prepareCapture();
            startActivityForResult(cameraHandler, CAPTURE_IDENTIFIER);
        }
    }



    private void initCamera(){
        cameraHandler = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraHandler.putExtra("return-data", true);
    }

    private void prepareCapture(){
        currentPhotoName = getNextImageIdentifier() + IMG_BASE_NAME;
        File image = new File(capturesFolder, currentPhotoName);
        Uri uriImage = Uri.fromFile(image);
        cameraHandler.putExtra(MediaStore.EXTRA_OUTPUT, uriImage);
    }



}

我检测到的异常是: RuntimeException:无法交付结果ResultInfo [...] NullPointerException

THe exception i have detected is: RuntimeException: failure delivering result ResultInfo [...] NullPointerException

我实际要做的是:

我必须用相机拍摄一张照片,然后在保存之前,必须对其进行处理.之后,我必须将其保存在SD卡中.但这对图像质量非常重要,我不能以低质量或至少不能过低的质量保存它.

I have to take a photo with the camera, then before save it, I have to process it. After that, i have to save it in SD card. But it's very important the image quality, I can't save it with low quality, or not too low quality at least.

推荐答案

我已经阅读了google文档,这是我的理解,但是我不确定100%:

I have been read the google documentation and this is what I understand, but I'm not sure 100%:

从android相机获取未压缩图像的唯一方法是将其保存在SD卡中.然后,如果要使用它,请从SD中获取它.

The only way to get an uncompressed image from the android camera is saving it in SD card. Then, if you want to use it, get it from SD.

实际上,由于意图只能传输"小"尺寸的对象,因此无法通过使用意图在活动之间传递未压缩的图像.

Indeed, it is not possible to pass an uncompressed image between activities by using intents due to intents can only "transport" objects of "small" size.

这篇关于Android不压缩即可保存位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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