Im looking for a way to use bitmap as input to Glide. I am even not sure if its possible. It\'s for resizing purposes. Glide has a good image enhancement with scale. The pro
A really strange case, but lets try to solve it. I'm using the old and not cool Picasso
, but one day I'll give Glide a try.
Here are some links that could help you :
And actually a cruel but I think efficient way to solve this :
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
Glide.with(this)
.load(stream.toByteArray())
.asBitmap()
.error(R.drawable.ic_thumb_placeholder)
.transform(new CircleTransform(this))
.into(imageview);
I'm not sure if this will help you, but I hope it can make you a step closer to the solution.
Please use Implementation for that is:
implementation 'com.github.bumptech.glide:glide:4.9.0'
Glide.with(this)
.asBitmap()
.load("http://url")
.into(new CustomTarget <Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition <? super Bitmap> transition) {
// you can do something with loaded bitmap here
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
The accepted answer works for previous versions, but in new versions of Glide use:
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(android.R.drawable.waiting);
requestOptions.error(R.drawable.waiting);
Glide.with(getActivity()).apply(requestOptions).load(imageUrl).into(imageView);
Courtesy
Most of the API's and methods of Glide are now deprecated. Below is working for Glide 4.9 and upto Android 10.
For image URI
Bitmap bitmap = Glide
.with(context)
.asBitmap()
.load(image_uri_or_drawable_resource_or_file_path)
.submit()
.get();
Use Glide as below in build.gradle
implementation 'com.github.bumptech.glide:glide:4.9.0'
In Kotlin,
Glide.with(this)
.asBitmap()
.load("https://...")
.addListener(object : RequestListener<Bitmap> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
Toast.makeText(this@MainActivity, "failed: " + e?.printStackTrace(), Toast.LENGTH_SHORT).show()
return false
}
override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
//image is ready, you can get bitmap here
return false
}
})
.into(imageView)