English 中文(简体)
申请: 摄像机——照片—— 低分辨率
原标题:App -> Camera -> Photo -> low resolution

问题:

When I use my app to take a photo and store it on SD, the resolution is 160x120. If using camera ordinary, resolution of photos is 1920x2560.

因此,请帮助我说,我必须做些什么来强迫照相机,从照相机开始,在标准高分辨率中拍照?

这是用于启动摄像意图和保存照片的代码一:

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();       } 
    }}

感谢你们!

问题回答

If you don t supply a uri for the output image, the camera intent will return only a thumbnail of the picture. Follow these instructions on how to do this properly: https://web.archive.org/web/20200222151624/http://www.tutorialforandroid.com/2010/10/take-picture-in-android-with.html

我也发现了同样的问题。 也许我们使用前线照相机。 我发现,还有一人使用照相机,发现密码被炸。

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);
        }

    }

}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签