napster
napster

Reputation: 717

How to load bitmap in touchimageview through Glide SDK 4.3.1?

Am trying to load a file as bitmap into TouchImageview. If I use normal image view instead of Touch image view Glide library is able to load image into it from file object but in case on touch image view Glide unable to load image.

Used following code as well:

 Glide.with(this).asBitmap().load(file).into(new SimpleTarget<Bitmap>(250, 250) {

            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                    touchImageView.setImageBitmap(resource);
            }

            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {
                super.onLoadFailed(errorDrawable);
            }
        });

But OnLoadFailed() is called with errorDrawable as null.

Upvotes: 3

Views: 794

Answers (1)

Ticherhaz FreePalestine
Ticherhaz FreePalestine

Reputation: 2377

Ok I just found about xml. please take note that, you HAVE TO USE RELATIVE LAYOUT!

 <RelativeLayout
        android:layout_width="match_parent"
        android:gravity="center"
        android:layout_height="match_parent">

        <my.zuhrain.kit.TouchImageView
            android:layout_marginTop="20dp"
            android:id="@+id/image_view_main"
            android:layout_width="400dp"
            android:layout_height="400dp" />

 </RelativeLayout>

and here we go

 storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                //things need to know
                //USE RELATIVE LAYOUT!
                Glide.with(getApplicationContext())
                        .asBitmap()
                        .load(uri)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                                touchImageView.setImageBitmap(resource);
                            }
                        });
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        });

Upvotes: 1

Related Questions