2011-02-23 2 views
1

의도를 통해 카메라를 열고 이미지를 SDCard의 폴더에 저장하려고합니다. 나는 이미지를 찍을 수 있고 이미지는 저장된다.카메라의 최대 해상도로 이미지를 저장할 수 없습니다.

하지만 문제는 축소판 해상도 이미지 (160 * 120) 크기 이미지를 저장하는 것입니다. 이것은 내가 뭐하는 거지입니다

...

imageFileFolder = new File(Environment.getExternalStorageDirectory(), 
      "MyApp"); 
    FileOutputStream out = null; 
    Calendar c = Calendar.getInstance(); 
    String date = fromInt(c.get(Calendar.MONTH)) 
      + fromInt(c.get(Calendar.DAY_OF_MONTH)) 
      + fromInt(c.get(Calendar.YEAR)) 
      + fromInt(c.get(Calendar.HOUR_OF_DAY)) 
      + fromInt(c.get(Calendar.MINUTE)) 
      + fromInt(c.get(Calendar.SECOND)); 
    imageFileName = new File(imageFileFolder, date.toString() + ".jpg"); 

    try 
    { 
     out = new FileOutputStream(imageFileName); 
     bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     out.flush(); 
     out.close(); 
     scanPhoto(imageFileName.toString()); 
     out = null; 

사람이 높은 저장에 도움을 주시겠습니까
mIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    mIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
      MediaStore.Images.Media.EXTERNAL_CONTENT_URI 
        .toString()); 
    mIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); 
    startActivityForResult(mIntent, PHOTO_SELECT); 

그리고 결과에 대한 활동에

... 카메라를 열려면 내가 가지고있는 해상도의 이미지 ...

+0

왜 사진에 EXTRA_VIDEO_QUALITY을 사용하고 있습니까? – Reno

+0

방금 ​​쐈어. 그 코드는 아무런 차이가 없었습니다. –

답변

1

나는 당신이 다음과 같은 클래스를 사용하여 캡쳐 이미지로 생각한다.

public class CameraApplication extends Activity implements 
     SurfaceHolder.Callback { 
    private static final String TAG = "cookbook.hardware"; 
    private LayoutInflater mInflater = null; 
    Camera mCamera; 
    byte[] tempdata; 
    boolean mPreviewRunning = false; 
    private SurfaceHolder mSurfaceHolder; 
    private SurfaceView mSurfaceView; 
    Button takepicture; 

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

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

    setContentView(R.layout.main); 

    mSurfaceView = (SurfaceView) findViewById(R.id.surface); 

    mSurfaceHolder = mSurfaceView.getHolder(); 
    mSurfaceHolder.addCallback(this); 
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 

    mInflater = LayoutInflater.from(this); 

    View overView = mInflater.inflate(R.layout.cameraoverlay, null); 
    this.addContentView(overView, new LayoutParams(
      LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

    takepicture = (Button) findViewById(R.id.button); 

    takepicture.setOnClickListener(new OnClickListener() { 
     public void onClick(View view) { 
      mCamera.takePicture(mShutterCallback, mPictureCallback, mjpeg); 
     } 
    }); 
} 

ShutterCallback mShutterCallback = new ShutterCallback() { 
    @Override 
    public void onShutter() { 
    } 
}; 
PictureCallback mPictureCallback = new PictureCallback() { 
    public void onPictureTaken(byte[] data, Camera c) { 
    } 
}; 
PictureCallback mjpeg = new PictureCallback() { 
    public void onPictureTaken(byte[] data, Camera c) { 
     if (data != null) { 
      tempdata = data; 
      done(); 
     } 
    } 
}; 

void done() { 
    Bitmap bm = BitmapFactory.decodeByteArray(tempdata, 0, tempdata.length); 
    String url = Images.Media.insertImage(getContentResolver(), bm, null, 
      null); 
    bm.recycle(); 
    Bundle bundle = new Bundle(); 
    if (url != null) { 
     bundle.putString("url", url); 
     Intent mIntent = new Intent(); 
     mIntent.putExtras(bundle); 
     setResult(RESULT_OK, mIntent); 
    } else { 
     Toast 
       .makeText(this, "Picture can not be saved", 
         Toast.LENGTH_SHORT).show(); 
    } 
    finish(); 
} 

@Override 
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
    Log.e(TAG, "surfaceChanged"); 
    try { 
     if (mPreviewRunning) { 
      mCamera.stopPreview(); 
      mPreviewRunning = false; 
     } 
     Camera.Parameters p = mCamera.getParameters(); 
     p.setPreviewSize(w, h); 
     mCamera.setParameters(p); 
     mCamera.setPreviewDisplay(holder); 
     mCamera.startPreview(); 
     mPreviewRunning = true; 
    } catch (Exception e) { 
     Log.d("", e.toString()); 
    } 
} 

@Override 
public void surfaceCreated(SurfaceHolder holder) { 
    Log.e(TAG, "surfaceCreated"); 
    mCamera = Camera.open(); 
} 

@Override 
public void surfaceDestroyed(SurfaceHolder holder) { 
    Log.e(TAG, "surfaceDestroyed"); 
    mCamera.stopPreview(); 
    mPreviewRunning = false; 
    mCamera.release(); 
    mCamera = null; 
} 
} 

main.xml에 .. 이제 카메라 MP ...있을 수에 따라 이미지와 이미지 해상도를 저장

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <SurfaceView android:id="@+id/surface" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    </SurfaceView> 
</LinearLayout> 

cameraoverlay.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="vertical" android:gravity="bottom" 
    android:layout_gravity="bottom"> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:orientation="horizontal" android:gravity="center_horizontal"> 
     <Button android:id="@+id/button" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="take picture" /> 
    </LinearLayout> 
</LinearLayout> 

를 T와하지 카메라 사용자 허가를 잊어 버림

<uses-permission android:name="android.permission.CAMERA"></uses-permission> 

이 응용 프로그램에서 작동 할 수 있습니다 ....

관련 문제