0
用800 * 480創建背景資源如果其他照片的寬度爲< = height.whatever這張照片的像素會變大或變大!老是唧唧的背景資源這張照片配合,照片必須是在後臺的資源範圍內招!我怎麼能明白嗎?謝謝java.lang.IllegalArgumentException:x width必須是<= bitmap.width()
private Bitmap scale(Bitmap origin) {
Bitmap bitmap = Bitmap.createBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.example_bg), 0, 0, 800, 480);
Canvas canvas = new Canvas(bitmap);
Rect target = null;
int orgWidth = origin.getWidth();
int orgHeight = origin.getHeight();
int bgHeight = bitmap.getHeight();
int bgWidth = bitmap.getWidth();
if (orgWidth * bgHeight > orgHeight * bgWidth) {
int newWidth = bgWidth, newHeight = newWidth * orgHeight/orgWidth;
target = new Rect(0, (bgHeight - newHeight)/2, newWidth,
(bgHeight + newHeight)/2);
} else {
int newHeight = bgHeight, newWidth = newHeight * orgWidth
/orgHeight;
target = new Rect((bgWidth - newWidth)/2, 0,
(bgWidth + newWidth)/2, newHeight);
}
canvas.drawBitmap(origin, null, target, new Paint(Paint.DITHER_FLAG
| Paint.FILTER_BITMAP_FLAG));
return bitmap;
}
這不是真的工作,如何在背景中的照片移動! – Goman