如何获取要插入到 Sqlite 中的 imageView 值?

How to get imageView value to insert in to Sqlite?

当我单击我的按钮时,我可以 select 照片并显示在我的 imageView 中。 但是当我点击保存的时候,我的imageView已经变成了NULL。任何人都可以帮助我吗? 位图总是为空。

我变了

Bitmap bitmap =  
((BitmapDrawable)imageViewProeto.getDrawable()).getBitmap();

Bitmap bitmap = imageViewProeto.getDrawingCache();

https://i.stack.imgur.com/S7gcN.jpg

BitmapDrawable draw = (BitmapDrawable) iv.getDrawable();

Bitmap bitmap = draw.getBitmap();

要将图像保存在您的图库中:

FileOutputStream outStream = null;
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/YourFolderName");
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
outStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();

刷新图库:

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

并且不要忘记在 Menifest.xml

中添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />