Hi i need help.i have created a camera application using android sdk 1.5.it works like this when open the application you have to click a button named "click" .When you click it camera will open and under the camera preview(another layer) thier is an button called "Take Pictuer". When you click the button camera takes the pictuer.it wokes fine to this point. I want to save the image in the Gallery in my dev phone 1. when i open the Gallery it will show the image with the resolution i set.But image has no pictuer and it is a black. no image is available
This is my code package img.cam; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import android.app.Activity; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Bitmap.CompressFormat; import android.hardware.Camera; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.provider.MediaStore.Images; import android.provider.MediaStore.Images.Media; import android.util.Log; import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; public class imgCam extends Activity { /** Called when the activity is first created. */ private Preview mPreview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button butt=(Button)findViewById(R.id.button); butt.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub mPreview = new Preview(getApplicationContext()); LinearLayout layout = new LinearLayout(getApplicationContext ()); LinearLayout layoutcam = new LinearLayout (getApplicationContext()); LinearLayout layoutbot = new LinearLayout (getApplicationContext()); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams ( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams ( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.height=360; lp2.height=60; layout.setOrientation(LinearLayout.VERTICAL); layoutcam.addView(mPreview); Button btn = new Button(getApplicationContext()); btn.setWidth(120); btn.setText("Take Pictuer"); layoutbot.addView(btn); layout.addView(layoutcam,lp); layout.addView(layoutbot,lp2); setContentView(layout); //listner for the button below camera btn.setOnClickListener(new OnClickListener(){ public void onClick(View v) { mPreview.pictake(); //save part ContentValues values = new ContentValues(); values.put(Images.Media.TITLE, "title"); values.put(Images.Media.BUCKET_ID, "test"); values.put(Images.Media.DESCRIPTION, "test Image taken"); values.put(Images.Media.MIME_TYPE, "image/jpeg"); Uri imageUri = getContentResolver().insert (Media.EXTERNAL_CONTENT_URI, values); OutputStream outstream; // Bitmap myPic = Bitmap.createBitmap(320, 240, false); Bitmap mypic=Bitmap.createBitmap(2048, 1536,Bitmap.Config.RGB_565); try { outstream = getContentResolver().openOutputStream(imageUri); mypic.compress(CompressFormat.JPEG, 25, outstream); outstream.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ); //end listner } } ); } } class Preview extends SurfaceView implements SurfaceHolder.Callback { SurfaceHolder mHolder; Camera mCamera; // new boolean mPreviewRunning = false; Preview(Context context) { super(context); // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. mCamera = Camera.open(); try { mCamera.setPreviewDisplay(holder); } catch (IOException exception) { mCamera.release(); mCamera = null; // TODO: add more exception handling logic here } } public void surfaceDestroyed(SurfaceHolder holder) { // Surface will be destroyed when we return, so stop the preview. // Because the CameraDevice object is not a shared resource, it's very // important to release it when the activity is paused. mCamera.stopPreview(); mCamera = null; } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (mPreviewRunning) { mCamera.stopPreview(); } Camera.Parameters p = mCamera.getParameters(); p.setPreviewSize(w, h); mCamera.setParameters(p); try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mCamera.startPreview(); mPreviewRunning = true; } Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { public void onPictureTaken(byte[] data, Camera c) { // Log.e(TAG, "PICTURE CALLBACK: data.length = " + data.length); mCamera.startPreview(); } }; public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return super.onKeyDown(keyCode, event); } if (keyCode == KeyEvent.KEYCODE_CAMERA) { mCamera.takePicture(null, mPictureCallback,null); return true; } return false; } public void pictake(){ mCamera.takePicture(null, mPictureCallback,null); } } Plz help me. Thanks in advance --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---