|
|
|
@ -28,6 +28,23 @@ public class YUVUtils {
|
|
|
|
|
return newbm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Bitmap rotateImage(Bitmap bm, int cameraRotationOffset) {
|
|
|
|
|
if (bm == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
int width = bm.getWidth();
|
|
|
|
|
int height = bm.getHeight();
|
|
|
|
|
Matrix matrix = new Matrix();
|
|
|
|
|
matrix.postRotate(360 - cameraRotationOffset);
|
|
|
|
|
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
|
|
|
|
|
true);
|
|
|
|
|
if (bm != null & !bm.isRecycled()) {
|
|
|
|
|
bm.recycle();
|
|
|
|
|
bm = null;
|
|
|
|
|
}
|
|
|
|
|
return newbm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//图片转YUV
|
|
|
|
|
public static byte[] getYUVByBitmap(Bitmap bitmap) {
|
|
|
|
|
if (bitmap == null) {
|
|
|
|
@ -90,6 +107,9 @@ public class YUVUtils {
|
|
|
|
|
width = Math.max(width, (int) Math.ceil(textPaint.measureText(split[i])));
|
|
|
|
|
}
|
|
|
|
|
int height = lineHeight * split.length;
|
|
|
|
|
// 宽高向上取偶数
|
|
|
|
|
width = (width + 1) / 2 * 2;
|
|
|
|
|
height = (height + 1) / 2 * 2;
|
|
|
|
|
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
@ -98,6 +118,9 @@ public class YUVUtils {
|
|
|
|
|
} else {
|
|
|
|
|
int width = (int) Math.ceil(textPaint.measureText(text));
|
|
|
|
|
int height = lineHeight;
|
|
|
|
|
// 宽高向上取偶数
|
|
|
|
|
width = (width + 1) / 2 * 2;
|
|
|
|
|
height = (height + 1) / 2 * 2;
|
|
|
|
|
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
|
canvas.drawText(text, 0, Math.abs(fontMetrics.ascent), textPaint);
|
|
|
|
|