Android-相机意图低位图质量 [英] Android - Camera intent low bitmap quality

查看:87
本文介绍了Android-相机意图低位图质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用android相机Intent拍照时,我得到的是低质量的位图图像.我想知道是否有可能使这种图像具有像样的质量.

When taking a picture using the android camera Intent, I get a low-quality bitmap image. I was wondering if it is possible to make this image decent quality.

我在Google上搜索了一些信息,我认为我必须使用'EXTRA_OUTPUT'( http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE )

I googled some information about it and I think that I have to use 'EXTRA_OUTPUT' (http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE)

我很挣扎,因为我不知道它在哪里放置,也不知道它是否可以解决我的问题.

I am struggling because I don't know where to place it and I don't know if it will solve my problem.

按btnTakePhoto后,我更改布局并打开android相机.位图以第二种布局显示(低质量). 这是我的代码:

After pressing btnTakePhoto, I change layout and open the android camera. The bitmap shows up in a second layout (low quality). Here is my code:

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Camera extends AppCompatActivity {
    ImageButton btnTakePhoto;
    ImageView imgTakenPhoto;
    private static final int CAM_REQUEST = 1313;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera);

        btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
        imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);


    btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
}
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == CAM_REQUEST){
            setContentView(R.layout.share);
            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
            imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);
            imgTakenPhoto.setImageBitmap(thumbnail);
        }
    }

    class btnTakePhotoClicker implements Button.OnClickListener {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAM_REQUEST);
        }
    }

    //CameraShare layout -- back button - Go back to first layout
    public void ibBackToPhotograph(View v) {
        setContentView(R.layout.camera);
        btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
        btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
    }
}

图像未保存在任何地方.接受后,它会在脸书上发布(snapchat)

The image isn't saved anywhere. It's ment to be posted on facebook after you accept it (snapchat)

推荐答案

请勿使用bitmap,而应使用uri.

 ImageView imageView;
 Uri image;
 String mCameraFileName;

 private void cameraIntent() {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);

        Date date = new Date();
        DateFormat df = new SimpleDateFormat("-mm-ss");

        String newPicFile = df.format(date) + ".jpg";
        String outPath = "/sdcard/" + newPicFile;
        File outFile = new File(outPath);

        mCameraFileName = outFile.toString();
        Uri outuri = Uri.fromFile(outFile);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outuri);
        startActivityForResult(intent, 2);
    }

  @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 2) {
                if (data != null) {
                    image = data.getData();
                    imageView.setImageURI(image);
                    imageView.setVisibility(View.VISIBLE);
                }
                if (image == null && mCameraFileName != null) {
                    image = Uri.fromFile(new File(mCameraFileName));
                    imageView.setImageURI(image);
                    imageView.setVisibility(View.VISIBLE);
                }
                File file = new File(mCameraFileName);
                if (!file.exists()) {
                    file.mkdir();
                }
            }
        }
    }

这篇关于Android-相机意图低位图质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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