我现在有一个View
,我正在尝试将其保存为固定大小,例如保存500*666
到 sdcard 中。图像保存成功,但图像保存如下。图像另存为整个图像的角落请参阅附图。
代码 :
private void onSave(final View v) {
v.setMinimumWidth(500);
v.setMinimumHeight(666);
Bitmap viewBitmap_save = null;
savingdialog();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(
dm);
Display display = getWindowManager()
.getDefaultDisplay();
viewBitmap_save = Bitmap.createBitmap(500, 666,
Bitmap.Config.ARGB_8888);// i
Canvas canvas = new Canvas(viewBitmap_save);
v.draw(canvas);
try {
Random randomGenerator = new Random();
long RANDOMFILENUMBER = randomGenerator
.nextLong();
File wallpaperDirectory = new File(
"/sdcard/Image Telling/");
// have the object build the directory
// structure, if needed.
wallpaperDirectory.mkdirs();
// create a File object for the output file
// FileOutputStream outStream = new
// FileOutputStream(file);
File outputFile = new File(wallpaperDirectory,
RANDOMFILENUMBER + ".png");
FileOutputStream outStream = new FileOutputStream(
outputFile);
viewBitmap_save.compress(CompressFormat.PNG,
100, outStream);
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment
.getExternalStorageDirectory())));
} catch (Exception e) {
// TODO: handle exception
}
}
我将宽度和高度作为修复,因为我需要图像作为固定大小。如何缩放视图?请帮我。