2

I am loading image from server using Glide with this code:

private void loadImage(Context context, String url, ImageView imageView, int x1, int y1, int x2, int y2) {
    Glide.with(context)
       .load(url)
       .into(imageView);
}

I need to show only piece of image in my ImageView. Coordinates of this piece placed in variables x1, x2, y1 and y2. How to cut only needed part of image using Glide?

Zoe
  • 27,060
  • 21
  • 118
  • 148
BArtWell
  • 4,176
  • 10
  • 63
  • 106

1 Answers1

5

AFAIK, there is no such an API in glide. But you can do that manually:

private void loadImage(Context context, String url, ImageView imageView, int x1, int y1, int x2, int y2) {
    Glide.with(context)
       .load(url)
       .asBitmap()
       .into(new SimpleTarget<Bitmap>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
            Bitmap cropeedBitmap = Bitmap.createBitmap(resource, x1, y1, x2, y2);
            imageView.setImageBitmap(cropeedBitmap);
        }
    });
}

Note, a relatively heavy Bitmap.createBitmap() operation is being performed on the main thread. You should consider doing that in background thread if that affects overall performance.

azizbekian
  • 60,783
  • 13
  • 169
  • 249