private Bitmap getBitmap(Rect cropRect, int scaleFactor) {
if(isRotated()) {
//noinspection SuspiciousNameCombination
cropRect = new Rect(cropRect.top, cropRect.left, cropRect.bottom, cropRect.right);
}
// TODO: there should be a way to do this without JPEG compression / decompression cycle.
YuvImage img = new YuvImage(data, imageFormat, dataWidth, dataHeight, null);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
img.compressToJpeg(cropRect, 90, buffer);
byte[] jpegData = buffer.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = scaleFactor;
Bitmap bitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, options);
// Rotate if required
if (rotation != 0) {
Matrix imageMatrix = new Matrix();
imageMatrix.postRotate(rotation);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), imageMatrix, false);
}
return bitmap;
}
SourceData.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:Viewer
作者:
评论列表
文章目录