该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
附一下保存图片的函数:
public void saveimg(){ if (bitmap2==null){ Toast toast=Toast.makeText(MainActivity.this,"图像尚未处理,无法保存",Toast.LENGTH_SHORT); toast.show(); } else { final MyAlertInputDialog myAlertInputDialog = new MyAlertInputDialog(this).builder() .setTitle("请输入") .setEditText(""); myAlertInputDialog.setPositiveButton("确认", new View.OnClickListener() { @Override public void onClick(View v) { myAlertInputDialog.dismiss(); String storepath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures"; String imgpath = myAlertInputDialog.getResult().toString() + ".jpg"; FileOutputStream fos = null; try { File file = new File(storepath, imgpath); fos = new FileOutputStream(file); bitmap2.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(), storepath, imgpath, null); } catch (FileNotFoundException e) { e.printStackTrace(); } sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + storepath + "/"+imgpath))); } }).setNegativeButton("取消", new View.OnClickListener() { @Override public void onClick(View v) { myAlertInputDialog.dismiss(); } }); myAlertInputDialog.show(); } }