0

I want to resize image use by glide . Now I use a picasso but I want to use a glide

private void resizeImg(Context context, final File file, int targetSize, Handler handler) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getPath(), options);

        float ratio = Math.max(options.outWidth, options.outHeight) / (float) targetSize;

        //don't scale image that is smaller than targetSize
        if (ratio < 1) return;

        int dstWidth = (int) (options.outWidth / ratio);
        int dstHeight = (int) (options.outHeight / ratio);

        PicassoTargetFactory.getInstance().putTarget(file, handler);

        Picasso.with(context)
                .load(file)
                .error(R.drawable.ic_delete)
                .resize(dstWidth, dstHeight)
                .into(PicassoTargetFactory.getInstance().getTarget(file));
        ArrayList<String> paths = new ArrayList<>();
        files = new ArrayList<>();
        files.add(mCurrentPhotoPath);
        for (File f : files) {
            paths.add(f.getAbsolutePath());
        }
        mdb.insertPhotos(paths);

    }

How I can do this ? On piccaso sometimes I have a cut image

Cœur
  • 37,241
  • 25
  • 195
  • 267
jpok2
  • 49
  • 1
  • 10

5 Answers5

1

first, add Glide lib in Gradle. Then, u can use it like this

Glide  
.with(context)
.load("your image path")
.override(600, 200) // resizes the image to these dimensions (in pixel). resize does not respect aspect ratio
.into(imageViewResize);
reza shams
  • 57
  • 4
1

Override must be accessed via RequestOptions in the most recent version of Glide.

Glide
.with(context)
.load(path)
.apply(new RequestOptions().override(600, 200))
.into(imageViewResizeCenterCrop);
Rishav Singla
  • 485
  • 4
  • 10
0

You can create RequestOptions class object & pass it on apply() method in Glide.

Use like,

Glide.with(context)
    .load(url)
    .apply(new RequestOptions().override(Your image size here))
    .into(imageView);

More From here

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
0

I think you should give your methods a single responsibility. You want a method that resizes an image but yours actually does more. Please separate things

private Bitmap resizeBitmap(Bitmap b, int w, int h) {
    // Your code.
    return myResizedBitmap;
}

Then it will be easier to help you

Hocine B
  • 391
  • 2
  • 8
0
private String getImgCachePath(String url) {
    FutureTarget<File> futureTarget = Glide.with(getBaseContext()).load(url).downloadOnly(100, 100);
    try {
        File file = futureTarget.get();
        String path = file.getAbsolutePath();
        return path;
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}

100,100 is width and height of image you want to save, change it as per your need. path is the path of cached image of given resolution of image url.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46