我有一个保存到SD卡的功能,我想在点击按钮保存后自动将它放在imageview上。请帮帮我,谢谢..
这是我的代码:我想让它放在tapimageview的ImageView上。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.createpage1);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
mTempDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + "PixiePhotos" + "/";
//mCurrent = "PXD_" + timeStamp + ".jpg";
prepareDirectory();
save = (Button)findViewById(R.id.save);
chooseimage = (Button)findViewById(R.id.chooseImage);
compositeImageView = (ImageView)findViewById(R.id.compositeImageView);
tapimageview = (ImageView) findViewById(R.id.tapimageview);
// imageView5 = (ImageView)findViewById(R.id.imageView5);
imageView4 = (ImageView) findViewById(R.id.imageView4);
imageView4.setOnTouchListener(this);
tapimageview.setImageURI(Uri.parse("android.resource://"
+ getPackageName() +"/"+R.raw.cork));
compositeImageView.setOnTouchListener(this);
chooseimage.setOnClickListener(this);
imageView4.setImageBitmap(drawingBitmap);
//tapimageview.setDrawingCacheEnabled(true);
//bgimage = tapimageview.getDrawingCache();
// tapimageview.draw(canvas);
//canvas.drawBitmap(bmp, 90, 0, paint);
save.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
Log.v(TAG, "Save Tab Clicked");
viewBitmap = Bitmap.createBitmap(600, 600, Bitmap.Config.ARGB_8888);//i is imageview whch u want to convert in bitmap
canvas = new Canvas(viewBitmap);
tapimageview.draw(canvas);
canvas.drawBitmap(bmp, 0, 0, paint);
canvas.drawBitmap(drawingBitmap, matrix, paint);
canvas.drawBitmap(bmpstickers, matrix, paint);
try {
mBitmapDrawable = new BitmapDrawable(viewBitmap);
mCurrent = "PXD_" + new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date()) + ".jpg";
mNewSaving = ((BitmapDrawable) mBitmapDrawable).getBitmap();
String FtoSave = mTempDir + mCurrent;
File mFile = new File(FtoSave);
mFileOutputStream = new FileOutputStream(mFile);
mNewSaving.compress(CompressFormat.JPEG, 100, mFileOutputStream);
mFileOutputStream.flush();
mFileOutputStream.close();
} catch (FileNotFoundException e) {
Log.v(TAG, "FileNotFoundExceptionError " + e.toString());
} catch (IOException e) {
Log.v(TAG, "IOExceptionError " + e.toString());
}
}
});
}
答案 0 :(得分:0)
回顾一下:
我认为只要文件存在于您指定的位置,您就应该能够按如下方式引用它:
mFile = new File(FtoSave);
if(mFile.exists()){
Bitmap mBitmap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
tapimageview.setImageBitmap(mBitmap);
}