Picasso cannot upload images for some URL (no special characters)

I use Picasso to upload some images from online to the View list. The problem is that some of the images have been successfully uploaded, some just disappear.

Successful (brand image successfully displayed):

enter image description here

Failed (brand image is not displayed, failed):

enter image description here

ImageView disappears when it fails. Here is my code:

Picasso.with(mContext)
.load(UrlEncoder.encode(interiorDesign.getBrand_image_url()))
.config(Bitmap.Config.RGB_565)
.error(R.drawable.blank)
.fit()
.centerInside()
.into(holder.brand);

Here is my .xml file:

<LinearLayout
android:layout_width="match_parent"
        android:layout_height="90dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_alignParentLeft="true"
        android:gravity="center_vertical"
        android:orientation="horizontal">

<RelativeLayout
android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingRight="10dp">
...
</RelativeLayout>

<ImageView
android:layout_width="200dp"
        android:layout_height="90dp"
        android:paddingBottom="10dp"
        android:id="@+id/partial_interior_design_brand" />
</LinearLayout>

I checked that it fails because it detects an error in the Picasso () error method.

Here is a link of the unsuccessful.

Here 's another bad link.

Here is a successful link.

. , fit() centerInside(), . .

+4
5

URL "http://". - picassa http://.

Picasso.with(mContext)
.load("http://".concatenate(url))
.config(Bitmap.Config.RGB_565)
.error(R.drawable.blank)
.fit()
.centerInside()
.into(holder.brand);
+2

Picasso , :

if (imageURL != null) {
    Picasso.with(getContext()).load(imageURL).error(R.drawable.ic_missing)
    .into(ivThumbnail);

:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/itemview_campaign_background"
    android:orientation="vertical"
    android:paddingBottom="5dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ImageView
        android:id="@+id/ivThumbnail"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

... // More stuff
0

Universal Image Loader, , Transform() Picasso targetHeight ImageView. CenterInside , imageView, , targetWidth ( ) . , targetWidth targetHeight.

            Picasso.with(mContext)
                    .load(url)
                    .transform(new Transformation() {
                        @Override
                        public Bitmap transform(Bitmap source) {
                            int targetHeight = dpToPx(height_dp);
                            double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
                            int targetWidth = (int) (targetHeight / aspectRatio);
                            if (targetWidth > dpToPx(width_dp)) {
                                targetWidth = dpToPx(width_dp);
                                targetHeight = (int) (targetWidth * aspectRatio);
                            }
                            Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
                            if (result != source) {
                                // Same bitmap is returned if sizes are the same
                                source.recycle();
                            }
                            return result;
                        }

                        @Override
                        public String key() {
                            return "transformation" + " desiredWidth";
                        }
                    })
                    .into(imageView);

private int dpToPx(int dp) {
    float density = Resources.getSystem().getDisplayMetrics().density;
    return Math.round((float) dp * density);
}

: , . .

0

UrlEncoder

.load(UrlEncoder.encode(interiorDesign.getBrand_image_url()))

URL

.load(interiorDesign.getBrand_image_url())
0

All Articles