java - android in onPreviewFrame method of image distortion . I will save the image to the SDcard in the following picture -


camera image data:

previewcallback previewcallback = new previewcallback() {          @override         public void onpreviewframe(byte[] data, camera camera) {             synchronized (nv21) {                 system.arraycopy(data, 0, nv21, 0, data.length);                 isnv21ready = true;             }         }     }; 

save image:

public void decodetobitmap( byte[] data, int mindex, int camera) {          try {              bitmap mbitmap = null;             camera.parameters parameters = mcamera.getparameters();             int format = parameters.getpreviewformat();             if (format == pixelformat.ycbcr_420_sp || format == pixelformat.ycbcr_422_i) {                 int w = parameters.getpreviewsize().width;                 int h = parameters.getpreviewsize().height;                 int[] = new int[data.length];                 decodeyuv420sp(i, data, w, h);                 mbitmap = bitmap.createbitmap(i, w, h, bitmap.config.argb_8888);             } else if (format == pixelformat.jpeg || format == pixelformat.rgb_565) {                 mbitmap = bitmapfactory.decodebytearray(data, 0, data.length);             }             if (mbitmap != null) {                 try {                     bitmap mbitmap = stutils.getrotatebitmap(mbitmap, -90);                     string face_path = getdirpath()+"/facecache/"+string.format("%04d.jpg", mindex);                     picutils.savebitmap(face_path, mbitmap);                     mbitmap.recycle();                     mbitmap = null;                 } catch (exception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }                 mbitmap.recycle();                 mbitmap = null;             }         } catch (exception ex) {             logg.e(tag, tag + "decodetobitmap error:" + ex.getmessage());         }     } 

image transfer format:

public void decodeyuv420sp(int[] rgb, byte[] yuv420sp, int width, int height) {      final int framesize = width * height;     (int j = 0, yp = 0; j < height; j++) {         int uvp = framesize + (j >> 1) * width, u = 0, v = 0;         (int = 0; < width; i++, yp++) {             int y = (0xff & ((int) yuv420sp[yp])) - 16;             if (y < 0)                 y = 0;             if ((i & 1) == 0) {                 v = (0xff & yuv420sp[uvp++]) - 128;                 u = (0xff & yuv420sp[uvp++]) - 128;             }             int y1192 = 1192 * y;             int r = (y1192 + 1634 * v);             int g = (y1192 - 833 * v - 400 * u);             int b = (y1192 + 2066 * u);             if (r < 0)                 r = 0;             else if (r > 262143)                 r = 262143;             if (g < 0)                 g = 0;             else if (g > 262143)                 g = 262143;             if (b < 0)                 b = 0;             else if (b > 262143)                 b = 262143;             rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);         }     } } 

i don't know why, error on part of phone. example xiaomi 5 phone.please @ wrong picture. enter image description here


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -