0

奇妙な問題が発生しています。ユーザーがボタンをクリックして画像を選択しています。次に、エンコードされたパスをdbに保存し、後で取得するため、別のアクティビティで画像を表示しますが、次の例外が発生します

09-14 01:39:36.195: W/System.err(2241): java.io.FileNotFoundException: No content provider: /external/images/media/1113
09-14 01:39:36.195: W/System.err(2241):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:610)
09-14 01:39:36.195: W/System.err(2241):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:542)
09-14 01:39:36.195: W/System.err(2241):     at android.content.ContentResolver.openInputStream(ContentResolver.java:377)

私のボタンOnClick&dbコードに保存:

                Uri selectedImage = imageReturnedIntent.getData();
                InputStream imageStream;
                try {
                    imageStream = getContentResolver().openInputStream(selectedImage);
                    BitmapFactory.Options options=new BitmapFactory.Options();
                    options.inSampleSize = 8;
                    Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );
                    ivPictureChosen.setImageBitmap(yourSelectedImage);
                    storeEncodedImageInDb(selectedImage.getEncodedPath());
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(this, "Couldn't pick image", Toast.LENGTH_SHORT).show();
                }

私の検索と画像コードの表示:

            String imagePath = db.getEncodedImage();
            if(imagePath.length()>0){
                Uri mainImgeUri = Uri.parse(imagePath);
                InputStream imageStream;
                try {
                    imageStream = getContentResolver().openInputStream(mainImgeUri);
                    BitmapFactory.Options options=new BitmapFactory.Options();
                    options.inSampleSize = 8;
                    Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream, null, options );
                    mainImage.setImageBitmap(yourSelectedImage);
                } catch (FileNotFoundException e) {

                    e.printStackTrace();
                }
            }

そもそもエンコードされたパスなのにファイルが見つからないのはなぜですか?

4

2 に答える 2

0

パスだけでなく、スキームなども必要になります。Uriは次のようになります: http://www.stackoverflow.comまたはfile://foo/bar/image.jpg。

encodePathは、これのパス部分のみです(例:stackoverflow.comまたは/foo/bar/image.jpg)。

yourUri.toString()の結果をデータベースに保存して取得してみてくださいUri.parse(theStringFromDatabase)

于 2012-09-14T06:02:26.533 に答える
0

これは、それをエンコードおよびデコードしてからbase64 string戻る方法base64 stringです。ご覧ください。

public static String encodeTobase64(String Path)
{
    Bitmap immagex=Bitmap.createScaledBitmap(BitmapFactory.decodeFile(Path), 140, 120, false);    
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    immagex.compress(Bitmap.CompressFormat.JPEG, 75, baos);
    byte[] b = baos.toByteArray();
    String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);

    Log.e("LOOK", imageEncoded);
    return imageEncoded;
}
public static Bitmap decodeBase64(String input) 
{
    byte[] decodedByte = Base64.decode(input, 0);
    return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); 
}
于 2013-04-22T06:41:51.497 に答える