Bitmap bitmapOrg;
try{
URL centreImageURL = new URL(hotelUrl);
URLConnection conn = centreImageURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bitmapOrg = BitmapFactory.decodeStream(is);
}
catch (Exception e) {
bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.hotel);
}
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 60;
int newHeight = 60;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(0);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
ImageView hotelImage=new ImageView(this);
hotelImage.setImageDrawable(bmd);
No comments:
Post a Comment