I am getting this when loading a Bitmap object into an ImageView
java.lang.IllegalArgumentException: Unknown type class android.graphics.Bitmap. You must provide a Model of a type for which there is a registered ModelLoader, if you are using a custom model, you must first call Glide#register with a ModelLoaderFactory for your custom model class
But its fine when I load a using the filepath. What is the problem here? I need to set the bitmap geneated into a particular ImageView.
You can't call load(Bitmap), it's not a supported type.
You could write a model loader/decoder etc for it, but it's probably more trouble than it's worth.
See also #122
Okay. Thanks for the prompt response. I will have to think of a different way.
No problem, feel free to follow that other issue if you're interested in doing this in the future.
noooooooooooooooooooo
we need glide for Bitmap
Use this:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Glide.with(this)
.load(stream.toByteArray())
.asBitmap()
.into(imageview);
Avoid UI thread.
Credit to Yurii Tsap
@a-maher I/O on UI thread? Compress just to decompress? What's wrong with imageview.setImageBitmap(yourBitmap)? What do you gain by this?
@TWiStErRob
Firstly all block in separated thread. I will add that to answer. Question was about using bitmap as input with Glide. For me it was because I have bitmap and I needed to use with Glide. There could be a reason to do that.. Your method is correct with double under normal situation but not in such as case. is it clear now 馃檪 ?
@a-maher it's not clearer 馃槥.
Firstly all block in separated thread.
No it doesn't, Glide....into(imageView) can only be called on UI thread, so compress is on UI thread as well. Just saying you shouldn't use it on UI thread doesn't change anything, because it not possible to call that method anywhere else.
For me it was because I have bitmap and I needed to use with Glide. There could be a reason to do that.
I totally agree, that's why I created the POCs in #122, those don't block and extremely fast.
@TWiStErRob Thanks for your time on reviewing and commenting.
Look I had a project where I should generate PDF. whole process is running under separated thread with RxJava. imageView will never be used in UI. It will be drawn with Canvas to build PDF.
crystal ? 馃
@a-maher aaah, that makes sense now, but you see it wasn't obvious from your code examples. Still you probably can't use Glide with .into(ImageView) because it is not prepared for that kind of usage.
@TWiStErRob I needed Glide because it is great tool for resizing images with best quality. It has so fart one of the best image processing algorithms. In my case I get output as bitmap which makes the call synchronous. Thanks again for enriching my post with your comments 馃憤
Most helpful comment
noooooooooooooooooooo
we need glide for Bitmap