首页 > 代码库 > ocrsearch的横屏转竖屏的解决方案

ocrsearch的横屏转竖屏的解决方案


//这是其中解决预览图的一部分(坑了好久的)
@Overridepublic void onPreviewFrame(byte[] data, Camera camera) { Size previewSize = camera.getParameters().getPreviewSize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] rawImage = null; // Decode image from the retrieved buffer to JPEG YuvImage yuv = new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null); yuv.compressToJpeg(new Rect(0, 0, previewSize.width, previewSize.height), YOUR_JPEG_COMPRESSION, baos); rawImage = baos.toByteArray(); // This is the same image as the preview but in JPEG and not rotated Bitmap bitmap = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length); ByteArrayOutputStream rotatedStream = new ByteArrayOutputStream(); // Rotate the Bitmap Matrix matrix = new Matrix(); matrix.postRotate(YOUR_DEFAULT_ROTATION); // We rotate the same Bitmap bitmap = Bitmap.createBitmap(bitmap, 0, 0, previewSize.width, previewSize.height, matrix, false); // We dump the rotated Bitmap to the stream bitmap.compress(CompressFormat.JPEG, YOUR_JPEG_COMPRESSION, rotatedStream); rawImage = rotatedStream.toByteArray(); // Do something we this byte array}

  转自:http://stackoverflow.com/questions/15131663/how-to-change-orientation-of-captured-byte-frames-through-onpreviewframe-callb

ocrsearch的横屏转竖屏的解决方案