【发布时间】:2011-05-14 21:13:40
【问题描述】:
我创建了一个位图,现在我想将该位图保存到某个目录中。谁能告诉我这是怎么做的。谢谢
FileInputStream in;
BufferedInputStream buf;
try {
in = new FileInputStream("/mnt/sdcard/dcim/Camera/2010-11-16_18-57-18_989.jpg");
buf = new BufferedInputStream(in);
Bitmap _bitmapPreScale = BitmapFactory.decodeStream(buf);
int oldWidth = _bitmapPreScale.getWidth();
int oldHeight = _bitmapPreScale.getHeight();
int newWidth = 2592;
int newHeight = 1936;
float scaleWidth = ((float) newWidth) / oldWidth;
float scaleHeight = ((float) newHeight) / oldHeight;
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
(我想将 _bitmapScaled 保存到我 SD 卡上的文件夹中)
【问题讨论】:
-
newWidth = 2592不是抛出内存不足异常吗? -
@MuhammadBabar 如果他只是将其保存到磁盘并且不在图像视图中使用它,则不会