简体   繁体   中英

android gestureimageview Image Uri

I'm using a GestureImageView Project that I've got from Github, I have several images in my drawable folder : page1.jpg, page2.jpg, page3.jpg,.........page30.jpg. I have a variable called pagenumber, when I click on a button this variable will increment, alson I want to load the image in the GestureImageView. Here is my code in the Main Class :

pagenumber++;

GestureImageView view1 = (GestureImageView) findViewById(R.id.image);

String uriPath = "android.resource://"+getPackageName()+"/drawable/page"+String.valueOf(pagenumber);

Uri uri = Uri.parse(uriPath);

view1 .setImageURI(uri);

In the GestureImageView.java the code is :

@Override
public void setImageURI(Uri mUri) {
    if ("content".equals(mUri.getScheme())) {
        try {
            String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};

            Cursor cur = getContext().getContentResolver().query(mUri, orientationColumn, null, null, null);

            if (cur != null && cur.moveToFirst()) {
                imageOrientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
            }  

            InputStream in = null;

            try {
                in = getContext().getContentResolver().openInputStream(mUri);
                Bitmap bmp = BitmapFactory.decodeStream(in);

                if(imageOrientation != 0) {
                    Matrix m = new Matrix();
                    m.postRotate(imageOrientation);
                    Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
                    bmp.recycle();
                    setImageDrawable(new BitmapDrawable(getResources(), rotated));
                }
                else {
                    setImageDrawable(new BitmapDrawable(getResources(), bmp));
                }
            }
            finally {
                if(in != null) {
                    in.close();
                }

                if(cur != null) {
                    cur.close();
                }
            }
        }
        catch (Exception e) {
            Log.w("GestureImageView", "Unable to open content: " + mUri, e);
        }
    }
    else {
        setImageDrawable(Drawable.createFromPath(mUri.toString()));
    }

    if (drawable == null) {
        Log.e("GestureImageView", "resolveUri failed on bad bitmap uri: " + mUri);
        // Don't try again.
        mUri = null;
    }
}

Well I'm having an empty image in the GestureImageView, it's not loading. The logcat says Unable to decode stream : java.io.FileNotFoundException: /android.resource:/com.example.tests/drawable/page3 : open failed : ENOENT (No such file or directory)

Any help please ?

Checkout: https://github.com/jasonpolites/gesture-imageview/issues/21

There is also:

GestureImageView goes blank when trying to set bitmap from camera programatically

Others in stackoverflow seemed to have the same problem and then fixed here :D (I feel sorry for myself having flagged this question and then finding the answer......)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM