-1

谁能给我一个方法来如何在数据库中保存图像的路径以及如何在 imageView 中显示图像。

4

1 回答 1

0

您可以通过这种方式存储图像并显示到imageview中。

String  path = Environment.getExternalStorageDirectory().toString()+ "/Directoryname";
String imageName;
File mFolder = new File();
                if (!mFolder.exists()) {
                    mFolder.mkdir(path);
                }
                  imageName= "yourimagename.jpg";
                //now you can store imagepath into database and imageto your sdcard so we can show image as per our requirement
                File file = new File (mFolder, imageName);
                if (file.exists ()) file.delete (); 
                Bitmap thumbnail = you can convert your image to bitmap and store into database.
                try {
                       FileOutputStream out = new FileOutputStream(file);
                       thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, out);
                       out.flush();
                       out.close();
                    } catch (Exception e) {
                       e.printStackTrace();
                    }

                //it will be store in your sdcard.

                //for displaying image into imageview
                File f = new File(path+"/"+imageName);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), options);
                iv.setImageBitmap(bitmap);

如果您发现任何问题,请告诉我。

于 2013-06-07T05:04:24.967 回答