is there is no one which help me in camera issue.

On Fri, Jul 15, 2011 at 4:40 PM, Ankit Kasliwal <kasliwalankit2...@gmail.com
> wrote:

> Hello Everyone,
>
> Is there anyway to reduce the resolution of picture taken using
> camera? It takes long time to upload the image to server Coz i m converting
> the image in bytes and
> send to server and may be the size of image may be 3 MB.
> Here is my code which i use.
>
>
> SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
>
>
>         public void surfaceCreated(SurfaceHolder holder)
>         {
>             mCamera=Camera.open();
>             try
>             {
>                 mCamera.setPreviewDisplay(previewHolder);
>                 mCamera.setOneShotPreviewCallback(null);
>                 ColorMatrix cm = new ColorMatrix();
>                 cm.setSaturation(.5f);
>
>
>                 //paint.setColorFilter(new ColorMatrixColorFilter(cm));
>
>             }
>             catch (Throwable t)
>             {
>                 Log.e("PictureDemo-surfaceCallback","Exception
> insetPreviewDisplay()", t);
>                 Toast.makeText(TakePic.this,t.getMessage(),
> Toast.LENGTH_LONG).show();
>             }
>         }
>
>         public void surfaceChanged(SurfaceHolder holder,int format, int
> width, int height) {
>             Camera.Parameters parameters=mCamera.getParameters();
>
>             /*int bestWidth = 0;
>               int bestHeight = 0;
>
>             //Customise width/height here - otherwise defaults to screen
> width/height
>             List<Camera.Size> previewSizes =
> parameters.getSupportedPreviewSizes();
>             if (previewSizes.size() > 1)
>             {
>                 Iterator<Camera.Size> cei = previewSizes.iterator();
>                 while (cei.hasNext())
>                 {
>                     Camera.Size aSize = cei.next();
>                     Log.v("SNAPSHOT","Checking " + aSize.width + " x " +
> aSize.height);
>                     if (aSize.width > bestWidth && aSize.width <=
> LARGEST_WIDTH
>                             && aSize.height > bestHeight && aSize.height <=
> LARGEST_HEIGHT)
>                     {
>                         // So far it is the biggest without going over the
> screen dimensions
>                         bestWidth = aSize.width;
>                         bestHeight = aSize.height;
>                     }
>                 }
>             }
>             if (bestHeight != 0 && bestWidth != 0)
>             {
>                 Log.v("SNAPSHOT", "Using " + bestWidth + " x " +
> bestHeight);
>                 parameters.setPreviewSize(bestWidth, bestHeight);
>                 View cameView = null;
>                 //cameraView.setLayoutParams(new LinearLayout.LayoutParams(
> bestWidth,bestHeight));
>             }*/  /*Not in 1.6*/
>
>              /*Not in 1.6*/
>             try
>             {
>                 parameters.setPreviewSize(100, 100);
>                 parameters.setPictureFormat(PixelFormat.JPEG);
>                 parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
>                 parameters.setJpegQuality(75);
>                 mCamera.setParameters(parameters);
>                 mCamera.startPreview();
>             }
>             catch (Exception e) {
>                 parameters.setPreviewSize(100, 100);
>                 parameters.setPictureSize(20, 20);//parameters.setZoom(1);
> /*Not in 1.6*/
>                 //parameters.setZoom(0); /*Not in 1.6*/
>                 parameters.setPictureFormat(PixelFormat.JPEG);
>
> //parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); /*Not in 1.6*/
>                 //parameters.setJpegQuality(100); /*Not in 1.6*/
>                 mCamera.setParameters(parameters);
>                 mCamera.startPreview();
>             }
>
>
>         //-- Must add the following callback to allow the camera
> toautofocus.
>             mCamera.autoFocus(new Camera.AutoFocusCallback(){
>                 public void onAutoFocus(boolean success, Camera camera)
>                 {
>                 }
>
>             } );
>         }
>
>         public void surfaceDestroyed(SurfaceHolder holder) {
>             if(mCamera != null){
>                 mCamera.stopPreview();
>                 mCamera.release();
>                 mCamera=null;
>             }
>         }
>     };
>
>     Camera.PictureCallback photoCallback=new Camera.PictureCallback() {
>         public void onPictureTaken(byte[] data, Camera camera) {
>
>
>             ImgName = String.format("%d.jpg", System.currentTimeMillis());
>             //FileOutputStream outStream = null;
>             try {
>
>
>                 byte[] imgBtye = data;
>
>                 ColorMatrix cm = new ColorMatrix();
>                 float contrast = 2;
>                 float brightness = -25;
>                 cm.set(new float[] { contrast, 0, 0, 0, brightness,0,
> contrast, 0, 0, brightness,0, 0, contrast, 0, brightness,    0, 0, 0,
> contrast, 0 });
>                 Paint paint = new Paint();
>                 cm.setSaturation(2f);
>                 paint.setColorFilter(new ColorMatrixColorFilter(cm));
>
>                 Log.d(TAG, "onPictureTaken - wrote bytes: " +
> imgBtye.toString());
>
>                 GetLocationService();
>
>                 Intent i = new Intent(TakePic.this, AddDetail.class);
>                    i.putExtra("Pimg", imgBtye);
>                    i.putExtra("lat", lat);
>                    i.putExtra("lag", lag);
>                    startActivity(i);
>
>             }
>             finally
>             {
>
>             }
>         }
>     };
>
>
>
> *And the other code which i use for convert and upload the image in Bytes
> *
> if(PImg != null)
>         {
>             try
>             {
>                 PImgString = Base64.encodeToString(PImg, 1);
>                 Log.d("PImgString", PImgString);
>             }
>             catch (Exception e) {
>                 PImgString = new String(PImgString);
>                 Log.d("PImgString catch", PImgString);
>             }
>         }
> --
>
> Thanks and Regards,
>
> Ankit Kasliwal
> kasliwalankit2...@gmail.com
> +91-9300-940-136
>



-- 

Thanks and Regards,

Ankit Kasliwal
kasliwalankit2...@gmail.com
+91-9300-940-136

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to