Task
1) Download the image from repository using picasso library
2) Add text and Image on specific coordinates on downloaded image. I don't want to use RelativeLayout. Can we do it using bitmap , canwas, drawable?
3) After adding Text and Image on specific coordinates load the Image on ImageView specified in Picasso.load() section [Please have a look at the code below].
How can I do that?
Example (Look at the heart and amount)
I am using picasso to download images:
private Target loadtarget;
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// do something with the Bitmap
handleLoadedBitmap(bitmap);
}
#Override
public void onBitmapFailed() {
}
}
Picasso.with(this).load(url).into(loadtarget);
}
public void handleLoadedBitmap(Bitmap b) {
// do something here
}
my ImageView.xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/img"
android:layout_width="match_parent"
android:layout_height="200dp"/>
Now I want to add text or image on above image (loaded by picasso) using bitmap and canvas. How can I do that?
Related
I am having trouble showing images correctly in my application.
I wish the picture would retain its original proportions. I display
picture in the AppBar,
I am using Picasso to download images, but cannot get the height and width of the downloaded image.
I've tried various solutions from other threads on StackOverflow, but unfortunately none of them work.
Can you help me get the height and width of the downloaded image using Picasso?
You can use bitmap target.
Load image in bitmap, get width and height and then set bitmap image in imageView. Glide library has the same feature.
Picasso.with(this).load(url).into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
imageView.setImageBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
I use Glide to load my image. I need to modify my image with a SimpleTarget callback, however when the image loaded to my list, and I scroll the list shows first always an other image, and than animate the right image after 1 second to the place. Without image modification and SimpleTarget everything works just fine. Here is my code.
#BindingAdapter("imageSrc")
public static void setImage(ImageView imageView, String url) {
Glide.with(imageView.getContext()).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
//the bitmap modified here
imageView.setImageBitmap(bmp);
}
});
}
is there any solution to avoid the flickering?
I am using a pager to controll multiple fragments, count depends on data input. Each fragment displays infos about a person, also a image. I am loading the image per Picasso library in each fragment. But the fragment doesnt update after the image was loaded and set to the ImageView, so it doesnt appear on the screen. If I am closing the fragments and open them again, all images are shown.
Is it possbile to update the fragments after loaded the images, so the images appear directly on the screen?
private void setHeaderImage() {
if (stolperstein.isImageHeaderUrl()) {
Picasso.with(getContext()).load(stolperstein.getImageHeaderUrl()).into(new Target() {
#Override
public void onPrepareLoad(Drawable arg0) {
}
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
user_header_photo.setBackground(drawable);
}
#Override
public void onBitmapFailed(Drawable arg0) {
}
});
}
}
I'm not exactly sure what you're doing in the last part of your code , but if user_header_photo is an ImageView you can load it directly into it:
Picasso.with(getContext()).load(stolperstein.getImageHeaderUrl()).into(user_header_photo)
I'm using picasso library for loading images from server into my application. my problem is when image loaded it has a triangle in top-left corner of image with color(like blue,green,red).
this is my code for loading image:
public static void loadDynamicImage(final String url, final Context context, final ImageView imageView, final int width, final int height){
Picasso.with(context).load(url)
.networkPolicy(NetworkPolicy.OFFLINE)
.resize(width,height)
.onlyScaleDown()
.into(imageView, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(context).load(url).resize(width,height).onlyScaleDown().into(imageView);
}
});
}
the image shown is :
You have enabled debug indicators on your Picasso instance (see official website). Look for setIndicatorsEnabled(true) in your code and remove it.
You have setIndicatorsEnabled set to true
Picasso picasso = Picasso.with(this);
picasso.setIndicatorsEnabled(false); //Or remove picasso.setIndicatorsEnabled(true);
Check this: Is there any way from which we can detect images are loading from cache in picasso?
I'm using Picasso class/library to load an image from an url and display the image to a ImageView. Is it possible for me to set the imageview loaded by the picasso image loader from an url as the background image of a linearlayout programmatically?
I've already found this issue - might be useful for you:
How do i set background image with picasso in code
According to that, Use callback of Picasso
Picasso.with(getActivity()).load(R.drawable.table_background).into(new Target(){
#Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
mainLayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
}
#Override
public void onBitmapFailed(final Drawable errorDrawable) {
Log.d("TAG", "FAILED");
}
#Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
Log.d("TAG", "Prepare Load");
}
})
Read also
Set background resource using Picasso
but there would you find the same solution.