簡體   English   中英

android gestureimageview Image Uri

[英]android gestureimageview Image Uri

我正在使用我從Github獲得的GestureImageView項目,我在drawable文件夾中有幾個圖像:page1.jpg,page2.jpg,page3.jpg,......... page30.jpg。 我有一個名為pagenumber的變量,當我點擊一個按鈕時,這個變量會遞增,alson我想在GestureImageView中加載圖像。 這是我在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);

在GestureImageView.java中,代碼是:

@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;
    }
}

好吧,我在GestureImageView中有一個空圖像,它沒有加載。 logcat說無法解碼流:java.io.FileNotFoundException:/android.resource:/com.example.tests/drawable/page3:open failed:ENOENT(沒有這樣的文件或目錄)

有什么幫助嗎?

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

還有:

嘗試以編程方式從攝像機設置位圖時,GestureImageView變為空白

stackoverflow中的其他人似乎有同樣的問題然后在這里修復:D(我為自己標記了這個問題然后找到答案而感到遺憾......)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM