I want to crop borders of image, that's parsing from json file. The Bitmap is handled inside the Targets callback methods. Also I use Picasso for setting image in ImageView. The problem is that extractThumbnail is used for ImageView, not for loaded picture.
getting image:
@Override
protected Boolean doInBackground(String... params) {
//....
String image = (jsonObject.getString("image"));
imageUrl = "https://dl.dropboxusercontent.com/u/999999/1/" + image;
hotel.setImage(imageUrl);
//...
}
@Override
protected void onPostExecute(Boolean result) {
//...
Picasso.with(getApplicationContext())
.load(hotel.getImage()) // thumbnail url goes here
.into(hotelImage, new Callback() {
@Override
public void onSuccess() {
Picasso.with(getApplicationContext())
.load(hotelUrl) // image url goes here
.placeholder(hotelImage.getDrawable())
.into(hotelImage);
}
@Override
public void onError() {
}
});
}
loadBitmap(hotel.getImage());
//...
}
loadBitmap method:
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
bitmap = ThumbnailUtils.extractThumbnail(bitmap, 150, 150, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
handleLoadedBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(getApplicationContext()).load(url).
placeholder(R.drawable.exhotel)
.into(hotelImage);
}
public void handleLoadedBitmap(Bitmap bitmap) {
// do something here
BitmapFactory.decodeResource(getResources(), R.id.hotelImage);
hotelImage.setImageBitmap(bitmap);
}
ImageView:
<ImageView
android:id="@+id/hotelImage"
android:layout_width="match_parent"
android:layout_height="@dimen/image_height"
android:minHeight="@dimen/image_height"
android:scaleType="centerCrop"
android:src="@drawable/exhotel"/>
What Could Possibly Go Wrong?
0 comments:
Post a Comment