1

I have app. I want to crop my picture that shown in imageview. I want crop with spesific length and width. can you help me? I have code but, that code crop direct from gallery.

I just want crop imageview with spesific length and width. Where length and width just input manual from user.

Maxim Pontyushenko
  • 2,983
  • 2
  • 25
  • 36
  • possible duplicate of http://stackoverflow.com/questions/13992535/android-imageview-scale-smaller-image-to-width-with-flexible-height-without-crop –  Sep 28 '13 at 09:07
  • No.... i am not to do centercrop. i want the length and width that input manual by user. just like input with inputbox on Java. can this work? – Dewi Wahyuni Sep 28 '13 at 09:16

1 Answers1

0

If you don't mind adding a new Library to your project just to do image loading for you, you can easily add Glide to crop your local drawables or images from the web.

In your build.gradle (module app)

compile 'com.github.bumptech.glide:glide:3.6.0'

You can crop the image with this below:

 final ImageView myImage = (ImageView) findViewById(R.id.myimageview);

        final int myWidth = 210;
        final int myHeight = 80;
        Glide.with(getApplicationContext())
                .load(R.drawable.example_drawable) // you can add any drawable or url of an image here
                .asBitmap()
                .into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                        // Do something with bitmap here.
                        Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, myWidth, myHeight);
                        myImage.setImageBitmap(bm);
                    }
                });
Tosin Onikute
  • 3,883
  • 6
  • 38
  • 61