android - ImageView bitmap scale dimensions -
i have bitmap larger imageview i'm putting in. have scaletype set center_inside. how dimensions of scaled down image?
ok. should have been clearer. needed height , width of scaled bitmap before it's ever drawn screen draw overlays in correct position. knew position of overlays in original bitmap not scaled. figured out simple formulas calculate should go on scaled bitmap.
i'll explain did in case else may 1 day need this.
i got original width , height of bitmap. imageview's height , width hard-coded in xml file @ 335.
int bitmap_width = bmp.getwidth(); int bitmap_height = bmp.getheight();
i determined 1 larger correctly figure out 1 base calculations off of. current example, width larger. since width scaled down the width of imageview, have find scaled down height. multiplied ratio of imageview's width bitmap's width times bitmap's height. division done last because integer division first have resulted in answer of 0.
int scaled_height = image_view_width * bitmap_height / bitmap_width;
with scaled height can determine amount of blank space on either side of scaled bitmap using:
int blank_space_buffer = (image_view_height - scaled_height) / 2;
to determine x , y coordinates of overlay should go on scaled bitmap have use original coordinates , these calculated numbers. x coordinate in example easy. since scaled width width of imageview, have multiply ratio of imageview's width bitmap's width original x coordinate.
int new_x_coord = image_view_width * start_x / bitmap_width;
the y coordinate bit trickier. take ratio of bitmap's scaled height bitmap's original height. multiply value original y coordinate. add blank area buffer.
int new_y_coord = scaled_height * start_y / bitmap_height + blank_space_buffer;
this works need. if height greater width, reverse width , height variables.
Comments
Post a Comment