Glide does not rotate images from camera correctly - android

I have a problem with Glide:
If I take a picture from Camera PORTRAIT mode (in my case Pixel XL), the image that is loaded later is rotated by 90° counter clock wise.
Used Glide:
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Here is my method to load images:
public class BetterRoundedImageView extends RoundedImageView {
private static final String TAG = BetterRoundedImageView.class.getSimpleName();
public BetterRoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Loads an image given by param url (this sets a default placeholder)
*
* #param url The url of the desired image to be loaded
*/
public void loadImage(final String url) {
loadImage(url, R.drawable.tracktics_logo);
}
/**
* Loads an image given by param url and a default placeholder while loading
*
* #param url The url of the desired image to be loaded
* #param placeholderResId the resource Id of the placeholder shown while loading image
*/
public void loadImage(final String url, #DrawableRes final int placeholderResId) {
Glide.with(getContext())
.asBitmap()
.load(url)
.circleCrop()
.placeholder(placeholderResId)
.into(BetterRoundedImageView.this);
}
}
This class is extending a RoundedImageView from
implementation 'com.makeramen:roundedimageview:2.3.0'
And it is used like this:
playerPhoto.loadImage(data.getProfilePictureUrl(), R.drawable.ic_default_profilepicture);
Can anyone help me out here?
Edit:
Maybe it has something to do how data is stored? In the Activity where I actually take the picture, the image is loaded correctly. But then when I go back to another view, the image is fetched from server (CDN) and cached locally to a Realm db.
Is there something that I miss when storing images on server by sending the base64 string to preserve exif information?

I resolved the issue by replacing the library:
https://github.com/MLSDev/RxImagePicker
by another Image Picker lib:
https://github.com/ArthurHub/Android-Image-Cropper
and now rotations are properly handled....
Seems like it was not a Glide issue after all!

I ran into the same issue, with this code, the image was rotated 90 degrees
Glide.with(activity).load(BitmapFactory.decodeFile(photoPath)).into(imgPicture)
Using this code it works as expected
Glide.with(activity).asBitmap().load(photoPath).into(imgPicture)
Not so much an answer, but maybe a hint to help you on your way.

Related

Android studio glide issue

I have this line of code on my android studio app
if (obj.getPhotoUrl() != null) {
ImageUtil.loadImage(GlideApp.with(context), obj.getPhotoUrl(), avatarImageView);
}
But it shows error "
Required type:
GlideRequests
Provided:
com.devlomi.fireapp.utils.glide.GlideRequests "
This is my MyAppGLideModule class
#GlideModule
public class MyAppGlideModule extends AppGlideModule {
#Override
public void registerComponents(Context context, Glide glide, Registry registry) {
registry.prepend(String.class, ByteBuffer.class, new Base64ModelLoaderFactory());
}
}
How to correct the error I want to load images using the Glide
if all you want is to load an image using Glide into an ImageView, then you don't need to extend any class inorder to use Glide.
you can just load the the image using its Uri with this line of code :
Glide.with(context).load(obj.getPhotoUrl()).into(avatarImageView);
if that's not what you meant in your question, can you explain more ?
With Glide Library it becomes a little easy to load the images from a url into an ImageView
And for this we use
Glide.with(getApplicationContext).load.(obj.getPhotoUrl()).into(imageView)

Loading resource id with Glide returns a noModelLoaderAvailableException

As far as I have seen, the way to load images via Resource Id is the same as loading normally from the internet:
Glide.with(fragmentContext).load(R.id.drawable).into(imageView);
(Although the way I'm loading it is slightly different, as I have dynamic resource images)
Glide.with(fragmentContext).load(R.drawable.class.getField("image_path_" + model.modelID))
.into(new CustomTarget<Drawable>() {
#Override
public void onResourceReady(#NonNull Drawable resource, #Nullable Transition<? super Drawable> transition) {
textView.setBackground(resource);
}
#Override
public void onLoadCleared(#Nullable Drawable placeholder) {
textView.setBackground(placeholder);
}
});
My image I'm trying to load is a .jpg saved in the drawable-nodpi folder.
When attempting to load the image in the onBindViewHolder in my recycler adapter, I get the following error:
com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: public static final int com.example.me.project.R$drawable.image
Does this have to do with my image format, or where it's saved in my assets/resource folders? I don't believe I have to implement a complex Model Loader for such a simple task.
Although the getField() snippet works when setting the resource of a View element, it doesn't work on Glide, as it expects specifically a resource Id, which is an int. Type Field != Int.
In this instance you have to explicitly get the Int resource Id from the resource.
Here would be the updated code to work with glide's image loader:
R.drawable.class.getField("name").getInt(null)

How to get the Uri path from a ImageView?

I am trying to create a wallpaper application. All images will come from internet.
Before of set as background, I need to crop the image. And for this, I am using an API named AndroidImageCropper. This API need of a URI object to execute the crop.
How can I get the Uri from ImageView? Because my image is from internet. The image is not on drawable folder. I am confusing. Maybe you guys can help me.
public class MainActivity extends AppCompatActivity {
private NetworkImageView imageView;
private Uri mCropImageUri;
public static final String URL_PHOTO = "http://cdn.wonderfulengineering.com/wp-content/uploads/2016/02/iron-man-wallpaper-42-610x1084.jpg";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (NetworkImageView) findViewById(R.id.image_view);
// Singleton for Volley API, Load image from internet
ImageLoader loader = MySingleton.getInstance(this).getImageLoader();
loader.get(URL_PHOTO, ImageLoader.getImageListener(imageView, R.drawable.temp_picture, android.R.drawable.ic_dialog_alert));
imageView.setImageUrl(URL_PHOTO, loader);
// Put the image on URI object
// #################################
// ### mCropImageUri = <-- ###
// #################################
}
// Action for my button
public void cropImage(View view) {
// API to crop an image
CropImage.activity(mCropImageUri)
.start(this);
}
}
Do you have any suggestion to me?
Thanks.
So you're using Volley? I'm not very familiar with Volley, both just some of my thoughts.
After image is downloaded to Android device, try to find the absolute path of the file and use android.net.Uri.fromFile to get a uri from the image.
Or else, can you use Bitmap object directly, instead of an uri.
OK, after some investigation, I think you have two solutions.
Using volley to download image as file, without using ImageLoader. In this way it's easy to get file uri of the image.
For Android-Image-Cropper, you can use Activity or use View(refer here). You can get the Bitmap object of the image in method onLoadingComplete of ImageLoadingListener. Then use com.theartofdev.edmodo.cropper.CropImageView to crop the image.

Image Manager - convert a URI from Google Play Game Services to a Drawable

I am getting the URI from google with this method:
Player me = Games.Players.getCurrentPlayer(mGoogleApiClient);
Uri uri = me.getHiResImageUri();
I read in various posts that because of Google's security restrictions I need to use the ImageManager class.
This class only provides voids which directly set the URI as the drawable for the ImageView I provide. This is the method: loadImage(ImageView imageView, Uri uri);
The problem is that I need to get a variable of the Drawable class from this Uri and use that. Having the Uri set as the drawable of the image does not work in my specific case.
I don't know if there is a class similar to ImageManager or if there is a workaround to get the drawable.
Thanks for all replies in advance!
One approach is to use HttpURLConnection and call the URL, you'll then get the InputStream and use it to instantiate a BitMap by decoding it thru BitmapFactory.decodeStream. As indicated by #señor-reginold-francis in his answer, don't forget to add the "User-agent" property as it may be denied access if its absent (considering you're getting it from a google domain)
You still have to determine yourself what you want to do with the image.
final ImageView imgView = (ImageView) findViewById(R.id.imageView);
ImageManager.create(context)
.loadImage(new ImageManager.OnImageLoadedListener() {
#Override
public void onImageLoaded(Uri uri, Drawable drawable, boolean b) {
imgView.setImageDrawable(drawable);
}
}, participant.getHiResImageUri(), R.drawable.placeholder);

Android + Volley: how to get image bitmap using ImageLoader?

I'm trying to get images for list view using Volley Library. I created simple HTTP helper with the following method.
/**
* Processing Image request and gets the image with given URL
*/
public Bitmap makeImageRequest(String url) {
ImageLoader il = new ImageLoader(queue, new BitmapLruCache());
il.get(url, new ImageLoader.ImageListener() {
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
mBitmap = processImageResponse(response);
}
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(Constants.Global.ERROR, "Error: " + error.getMessage());
mBitmap = null;
}
});
return mBitmap;
}
But problem is that:
new BitmapLruCache()
Method is not recognized.
So i tried to create ImageLoader using the following code which i found on the URL:
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
But in thos code i cannot find out where to get
AppController
Because the method code is triggered from the custom
public class HttpHelperClass
And called from the activity using the:
// Try to load remote image from URL
Bitmap bm = http.makeImageRequest("http://camranger.com/wp-content/uploads/2014/10/Android-Icon.png");
ImageView iv = (ImageView) findViewById(R.id.imageView);
iv.setImageBitmap(bm);
Is it the right approach how to load images and how can i repair my code to make succcessfull request?
Many thanks for any advice.
I think your makeImageRequest method will always return null because it takes some time for the onResponse or onErrorResponse listeners to get called but you return the mBitmap immidately!
If you want to use Volley's ImageLoader you'd better get image inside your activity or ... not from another class like your HttpHelperClass.
Also AppController is a class that extends Application and you should create it yourself. (It's in your AndroidHive link. Section 3. Creating Volley Singleton class)
And also for caching images you should not create a new ImageLoader everytime because in this way the caching gets meaningless. You should get that from your AppController class.
Furthermore I suggest you using Picasso because it's way better that Volley in image loading and a lot easier!
With Picasso you only need to call the following line to load an image from web into an ImageView:
Picasso.with(context).load(urlString).to(imageView);

Categories

Resources