[英]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. 我正在使用我从Github获得的GestureImageView项目,我在drawable文件夹中有几个图像: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. 我有一个名为pagenumber的变量,当我点击一个按钮时,这个变量会递增,alson我想在GestureImageView中加载图像。 Here is my code in the Main Class : 这是我在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 : 在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;
}
}
Well I'm having an empty image in the GestureImageView, it's not loading. 好吧,我在GestureImageView中有一个空图像,它没有加载。 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) logcat说无法解码流:java.io.FileNotFoundException:/android.resource:/com.example.tests/drawable/page3:open failed:ENOENT(没有这样的文件或目录)
Any help please ? 有什么帮助吗?
Checkout: https://github.com/jasonpolites/gesture-imageview/issues/21 结帐: https : //github.com/jasonpolites/gesture-imageview/issues/21
There is also: 还有:
GestureImageView goes blank when trying to set bitmap from camera programatically 尝试以编程方式从摄像机设置位图时,GestureImageView变为空白
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......) stackoverflow中的其他人似乎有同样的问题然后在这里修复:D(我为自己标记了这个问题然后找到答案而感到遗憾......)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.