im having an image(some dimensions) i set the width of some pixel position. i need a java method to calculate the height of the image to display properly...
please help me.... urgent..
im having an image(some dimensions) i set the width of some pixel position. i need a java method to calculate the height of the image to display properly...
please help me.... urgent..
Do you mean you want to maintain the original aspect ratio, you're changing the width and you want to know the height? If so, it should be something like:
int newHeight = (oldHeight * newWidth) / oldWidth;
Performing multiplication then division will avoid some rounding errors, but may fail if the image is huge (i.e. if it overflows). An alternative is to use floating point:
int newHeight = (int) (oldHeight * ((double) newWidth / oldWidth));
Are you doing it in BLackberry appln,if so use Display.getWidth() to calculate