80,349
社区成员
发帖
与我相关
我的任务
分享
setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeFile("/storage/sdcard/bg.jpg")));
myCanvas.save(Canvas.ALL_SAVE_FLAG);
myCanvas.restore();
File f = new File("/storage/sdcard/","bg.jpg");
if(f.exists()){
f.delete();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
myBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
try {
fos.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
try {
String url=ImageUrl.getImageUrl();
Bitmap bmp = BitmapFactory.decodeFile(url);
if (null != bmp){
touchView.setBkBitmap(bmp);
}
} catch (Exception e) {
// TODO: handle exception
}
}
自定义View中的
public void setBkBitmap(Bitmap bmp)
{
Drawable drawable=new BitmapDrawable(bmp);
setBackgroundDrawable(drawable);
invalidate();
}
并不能替换背景,图片也是保存在SD卡中