android - Bad Quality on Camera Preview -


i making android app using camera api. having trouble picture preview (after picture has been taken). issues are: 1) quality of image poor , blurred 2) rotation of picture 270 degrees rotated. 3) picture preview without zoom if zoom in live preview.

please me these problems. need save pictures sd card. how should it?

my source preview is:

public static bitmap decodestrem(file fil, uri selectedimage,                                      context mcontext) {          bitmap bitmap = null;         try {              bitmap = bitmapfactory.decodestream(mcontext.getcontentresolver()                     .openinputstream(selectedimage));              final int thumbnail_size = getthumbsize(bitmap);              bitmap = bitmap.createscaledbitmap(bitmap, thumbnail_size,                     thumbnail_size, false);              bytearrayoutputstream baos = new bytearrayoutputstream();             bitmap.compress(bitmap.compressformat.jpeg, 100, baos);             bitmap = bitmapfactory.decodestream(new bytearrayinputstream(baos                     .tobytearray()));              return bitmap = rotateimage(bitmap, fil.getabsolutepath());          } catch (exception e) {             e.printstacktrace();         }         return bitmap;     }     public static bitmap rotateimages(bitmap bmp, string imageurl) {         if (bmp != null) {             exifinterface ei;             int orientation = 0;             try {                 ei = new exifinterface(imageurl);                 orientation = ei.getattributeint(exifinterface.tag_orientation,                         exifinterface.orientation_normal);              } catch (ioexception e) {                 e.printstacktrace();             }             int bmpwidth = bmp.getwidth();             int bmpheight = bmp.getheight();             matrix matrix = new matrix();             switch (orientation) {                 case exifinterface.orientation_undefined:                     matrix.postrotate(90);                     break;                 case exifinterface.orientation_rotate_90:                     matrix.postrotate(90);                     break;                 case exifinterface.orientation_rotate_180:                     matrix.postrotate(180);                     break;                 case exifinterface.orientation_rotate_270:                     matrix.postrotate(270);                     break;                 default:                     break;             }             bitmap resizedbitmap = bitmap.createbitmap(bmp, 0, 0, bmpwidth,                     bmpheight, matrix, true);             return resizedbitmap;         } else {             return bmp;         }     }      public static bitmap decodefile(file f, int sampling) {         try {             bitmapfactory.options o2 = new bitmapfactory.options();             o2.injustdecodebounds = true;             bitmapfactory.decodestream(                     new fileinputstream(f.getabsolutepath()), null, o2);              o2.insamplesize = sampling;             o2.intempstorage = new byte[48 * 1024];              o2.injustdecodebounds = false;             bitmap bitmap = bitmapfactory.decodestream(                     new fileinputstream(f.getabsolutepath()), null, o2);             bytearrayoutputstream baos = new bytearrayoutputstream();             bitmap.compress(bitmap.compressformat.jpeg, 100, baos);             bitmap = rotateimage(bitmap, f.getabsolutepath());             return bitmap;          } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (outofmemoryerror e) {             e.printstacktrace();         }         return null;     }      public static bitmap rotateimage(bitmap bmp, string imageurl) {         if (bmp != null) {             exifinterface ei;             int orientation = 0;             try {                 ei = new exifinterface(imageurl);                 orientation = ei.getattributeint(exifinterface.tag_orientation,                         exifinterface.orientation_normal);              } catch (ioexception e) {                 e.printstacktrace();             }             int bmpwidth = bmp.getwidth();             int bmpheight = bmp.getheight();             matrix matrix = new matrix();             switch (orientation) {                 case exifinterface.orientation_undefined:                     matrix.postrotate(90);                     break;                 case exifinterface.orientation_rotate_90:                     matrix.postrotate(90);                     break;                 case exifinterface.orientation_rotate_180:                     matrix.postrotate(180);                     break;                 case exifinterface.orientation_rotate_270:                     matrix.postrotate(270);                     break;                 default:                     break;             }             bitmap resizedbitmap = bitmap.createbitmap(bmp, 0, 0, bmpwidth,                     bmpheight, matrix, true);             return resizedbitmap;         } else {             return bmp;         }     }      public static int getthumbsize(bitmap bitmap) {          int thumbnail_size = 250;         if (bitmap.getwidth() < 300) {             thumbnail_size = 250;         } else if (bitmap.getwidth() < 600) {             thumbnail_size = 500;         } else if (bitmap.getwidth() < 1000) {             thumbnail_size = 750;         } else if (bitmap.getwidth() < 2000) {             thumbnail_size = 1500;         } else if (bitmap.getwidth() < 4000) {             thumbnail_size = 2000;         } else if (bitmap.getwidth() > 4000) {             thumbnail_size = 2000;         }         return thumbnail_size;     } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -