读懂它就可以了。
Integer[] picTbl = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7,
R.drawable.pic8,
R.drawable.pic9,
R.drawable.pic10
};
//把所有的图先保存到Sd卡本地
void AllSaveBitmap()
{
String FileStr ="/pic";
String FileStr1="";
int k = 0;
for(int i = 0 ; i < 10 ;i++)
{
k = i +1;
FileStr1 = FileStr + k+".PNG";
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
opt.inPurgeable = true;
opt.inInputShareable = true;
bitmap = BitmapFactory.decodeFile("/sdcard/pic/" +FileStr1,opt);
if(bitmap == null)
{
mBitmap = ReadBitMap(mContext, picTbl);//
mBitmapWidth = mBitmap.getWidth();
mBitmapHeight = mBitmap.getHeight();
bitmap=Bitmap.createScaledBitmap (mBitmap,mBitmapWidth,mBitmapHeight,true);
//FileStr = FileStr + k+".PNG";
SaveBitmap(bitmap,FileStr1);
}
}
}
//保存到本地
public void SaveBitmap(Bitmap bmp,String FileStr)
{
Bitmap bitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
// Bitmap bitmap=Bitmap.createScaledBitmap (bmp,bmp.getWidth(), bmp.getHeight(),true);
Canvas canvas = new Canvas(bitmap);
//加载背景图片
// Bitmap bmps = BitmapFactory.decodeResource(getResources(), R.drawable.playerbackground);
// canvas.drawBitmap(bmps, 0, 0, null);
//加载要保存的画面
canvas.drawBitmap(bmp, 0, 0, null);
//保存全部图层
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
//存储路径
File file = new File("/sdcard/pic/");
if(!file.exists())
file.mkdirs();
try {
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath() + FileStr);//"/xuanzhuan.jpg");
bmp.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
fileOutputStream.close();
System.out.println("saveBmp is here");
} catch (Exception e) {
e.printStackTrace();
}
}
如何通过文件流将很多图片存入SD卡,而不是自己内存
精选 转载文章标签 如何通过文件流将很多图片存入SD卡 而不是自己内存 文章分类 后端开发
-
图片保存到sd卡
import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOExceptio
Android Java OS android java -
SD卡文件浏览
activity_mai.xml:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/androrent" android:lay
SD卡读写文件 File存储 android xml java