Reputation: 1300
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 ?
Upvotes: 3
Views: 734
Reputation: 707
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......)
Upvotes: 2