將ImageView中的圖片保存到本地相冊

cwf8 9年前發布 | 6K 次閱讀 Java Android

    private void SaveImageToSysAlbum() {
if (FileUtil.isSdCardExist()) {
BitmapDrawable bmpDrawable = (BitmapDrawable)mFullImageView.getDrawable();
Bitmap bmp = bmpDrawable.getBitmap();
if (bmp != null) {
try {
ContentResolver cr = getContentResolver();
String url = MediaStore.Images.Media.insertImage(cr, bmp,
String.valueOf(System.currentTimeMillis()), "");
Toast.makeText(this, getString(R.string.save_succ), Toast.LENGTH_SHORT).show();

                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
            }else {  
                Toast.makeText(this, getString(R.string.no_iamge_save_fail), Toast.LENGTH_SHORT).show();  
            }  
        }else {  
            Toast.makeText(this, getString(R.string.no_sdcard_save_fail), Toast.LENGTH_SHORT).show();  
        }  
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));  
    }  </pre> 


 本文由用戶 cwf8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!