1
我想調整圖像和我用下面的代碼做它:BitmapFactory.Options inSampleSize作物圖像
public Bitmap createWatermark(Bitmap src, String watermark, int x, int y) {
Log.d("Original Dimensions", src.getWidth() + " x " + src.getHeight());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
src.compress(Bitmap.CompressFormat.JPEG, 30, stream);
byte[] byte_arr = stream.toByteArray();
Bitmap result = BitmapFactory.decodeByteArray(byte_arr, 0, byte_arr.length, options).copy(Bitmap.Config.ARGB_8888, true);
Log.d("Result Dimensions", result.getWidth() + " x " + result.getHeight());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.YELLOW);
paint.setTextSize(40);
canvas.drawText(watermark, x, y, paint);
paint.setColor(Color.BLACK);
canvas.drawText(watermark, x, y+50, paint);
return result;
}
的日誌如下:
d /原始尺寸(11180): 1920×2560
d /結果尺寸(11180):960×1280
但返回被裁剪到960×1280,而不是重新調整大小的圖像。