我把屏幕1280х720的图像播放到屏幕1920х720上,但是我不能把它正确地放在新屏幕上。告诉我如何正确放置它。
private static final int WIDTH = 1920;
private static final int HEIGHT = 720;
private int mWidth;
private int mHeight;
private Bitmap canvas = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
private void processImage(Image image) {
Bitmap bitmap = null;
try {
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * mWidth;
// create bitmap
bitmap = Bitmap.createBitmap(mWidth + rowPadding / pixelStride, mHeight, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
int newWidth = mWidth * HEIGHT / mHeight;
Rect src = new Rect(0, 0, mWidth, mHeight);
Rect dst = new Rect(WIDTH/2-newWidth/2, 0, WIDTH/2+newWidth/2, HEIGHT);
new Canvas(canvas).drawBitmap(bitmap, src, dst, null);
// write bitmap
ByteArrayOutputStream os = new ByteArrayOutputStream();
canvas.compress(Bitmap.CompressFormat.JPEG, 100, os);
mProj.setData(os.toByteArray());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bitmap != null) {
bitmap.recycle();
}
}
}