首页 > 代码库 > 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的横屏转竖屏的解决方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。