I want to control the horizontal crop of an ImageView
using a SeekBar
, like presented in this photo:
This is my code for the progressChanged
event:
cropSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float tuning = (float) progress/seekBar.getMax();
if (tuning == 0) {
return;
}
int width = (int)(tuning * originalPhotoBitmap.getWidth());
int height = originalPhotoBitmap.getHeight();
modifiedPhotoBitmap = Bitmap.createBitmap(originalPhotoBitmap, 0, 0, width, height);
imageView.setImageBitmap(modifiedPhotoBitmap);
}
});
The new width is calculated correctly (I checked the value in logcat), but when I set the imageView's bitmap with setImageBitmap
it appears that the ScaleType FIT_CENTER
isn't working anymore...
What I'm actually getting with my code is this:
Progress value: 100
Progress value: 50
Progress value: 25
As you can see, it is not the desired behavior...
My questions are two:
- What scale type should I use in the ImageView?
- Is my new bitmap defined correctly?