应用程序 - >相机 - >图片 - >低分辨率(App -> Camera ->

2019-06-23 10:29发布

问题:

当我用我的应用程序拍照并存储到SD,分辨率160×120是。 如果使用普通相机,照片分辨率为俄语动词。

所以,请帮我说什么,我要做给力的相机,开始从应用程序,采取在标准高分辨率的照片?

这是我用相机开始意图和保存照片的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(cameraIntent, CAMERA_REQUEST); 
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST) { 

    Bundle xz = data.getExtras();
    if (xz!=null) {

    Bitmap image = (Bitmap) data.getExtras().get("data");

    String filePath = "/mnt/sdcard/DCIM/"; 
    filePath += "hml.png";
 try {
  image.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(new File(filePath)));
 } 
    catch (FileNotFoundException e) {
                 // TODO Auto-generated catch block
                e.printStackTrace();}  
    catch (NullPointerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();       } 
    }}

谢谢!

Answer 1:

如果不输出图像提供一个URI,相机意图仅返回图片的缩略图。 按照有关如何做到这一点正确这些指令: http://www.tutorialforandroid.com/2010/10/take-picture-in-android-with.html



Answer 2:

我发现了同样的问题。 也许我们使用前置摄像头。 我发现,还有另一种使用摄像头和查找代码打击。

AndroidManifest.xml中:

    </application>
    <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/></manifest>

源代码:

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private CameraView cv;
    private Camera mCamera = null;
    private Bitmap mBitmap = null; 

    public Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {

        public void onPictureTaken(byte[] data, Camera camera) {
            Log.i("yao","onPictureTaken");
            Toast.makeText(getApplicationContext(), "saving……", Toast.LENGTH_LONG).show();
            mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            File file = new File("/sdcard/YY"+ new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg");
            try {
                file.createNewFile();
                BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
                mBitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
                os.flush();
                os.close();
                Toast.makeText(getApplicationContext(), "save completed", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);

        FrameLayout  fl = new FrameLayout(this);     

        cv = new CameraView(this);
        fl.addView(cv);

        TextView tv = new TextView(this);
        tv.setText("take a picture");
        fl.addView(tv);

        setContentView(fl);

    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.i("yao","MainActivity.onKeyDown");
        if (keyCode == KeyEvent.KEYCODE_CAMERA) {
            if (mCamera != null) {
                Log.i("yao","mCamera.takePicture");
                mCamera.takePicture(null, null, pictureCallback);
            }
        }
        return cv.onKeyDown(keyCode, event);
    }

    class CameraView extends SurfaceView {

        private SurfaceHolder holder = null;

        public CameraView(Context context) {
            super(context);
            Log.i("yao","CameraView");

            holder = this.getHolder();
            holder.addCallback(new SurfaceHolder.Callback() {

                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                    mCamera.stopPreview();
                    mCamera.release();
                    mCamera = null;
                }

                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    mCamera = Camera.open();
                    try {
                        mCamera.setPreviewDisplay(holder);
                    } catch (IOException e) {
                        mCamera.release();
                        mCamera = null;
                    }

                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

                    Camera.Parameters parameters = mCamera.getParameters();
                    parameters.setPictureFormat(PixelFormat.JPEG);
                    parameters.setPreviewSize(854, 480);
                    parameters.setFocusMode("auto");
                    parameters.setPictureSize(2592, 1456);
                    mCamera.setParameters(parameters);
                    mCamera.startPreview();
                }
            });
            holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }

    }

}


文章来源: App -> Camera -> Photo -> low resolution