0
在這裏,我將生成Qr代碼作爲圖像視圖。我想將該圖像文件保存到手機圖庫中。請幫幫我。如何將我的QR生成的圖像保存到圖庫android?
在這裏,我將生成Qr代碼作爲圖像視圖。我想將該圖像文件保存到手機圖庫中。請幫幫我。如何將我的QR生成的圖像保存到圖庫android?
首先在這裏使用下面的代碼
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
現在保存此位在內部存儲
private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
Log.d(TAG,
"Error creating media file, check storage permissions: ");// e.getMessage());
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
}
/** Create a File for saving an image or video */
private File getOutputMediaFile(){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new
File(Environment.getExternalStorageDirectory()
+ "/Android/data/"
+ getApplicationContext().getPackageName()
+ "/Files");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
File mediaFile;
String mImageName="MI_"+ timeStamp +".jpg";
mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
return mediaFile;
}
感謝ji..here是我的代碼 –
給予好評這個答案:) –
創建ImageView的位圖我正在生成qr代碼.. bitmap = TextToImageEncode(EditTextValue); imageView.setImageBitmap(bitmap);我如何將imageview轉換爲位圖? –