+
+ /**
+ * Takes suggested float scale, int width, int height and create a bounding
+ * box returned as a BitmapImageSizing object with consistent scale, width,
+ * height fields.
+ *
+ * @param scale
+ * @param bitmapwidth
+ * @param bitmapheight
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing getScaleWidthHeight(int width, int height,
+ float scale, int bitmapwidth, int bitmapheight)
+ {
+ float usescale = 0.0f;
+ int usewidth = width;
+ int useheight = height;
+
+ // use the smallest positive scale (i.e. fit in the box)
+ if (scale > 0.0f)
+ {
+ usescale = scale;
+ usewidth = Math.round(scale * width);
+ useheight = Math.round(scale * height);
+ }
+ if (bitmapwidth > 0)
+ {
+ float wscale = (float) bitmapwidth / width;
+ if (wscale > 0.0f && (usescale == 0.0f || wscale < usescale))
+ {
+ usescale = wscale;
+ usewidth = bitmapwidth;
+ useheight = Math.round(usescale * height);
+ }
+ }
+ if (bitmapheight > 0)
+ {
+ float hscale = (float) bitmapheight / height;
+ if (hscale > 0.0f && (usescale == 0.0f || hscale < usescale))
+ {
+ usescale = hscale;
+ usewidth = Math.round(usescale * width);
+ useheight = bitmapheight;
+ }
+ }
+ return new BitmapImageSizing(usescale, usewidth, useheight);
+ }
+
+ /**
+ * Takes suggested scale, width, height as a BitmapImageSizing object and
+ * create a bounding box returned as a BitmapImageSizing object with
+ * consistent scale, width, height fields.
+ *
+ * @param bis
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing getScaleWidthHeight(int width, int height,
+ BitmapImageSizing bis)
+ {
+ return ImageMaker.getScaleWidthHeight(width, height, bis.scale,
+ bis.width, bis.height);
+ }
+
+ /**
+ * Takes String versions of suggested float scale, int width, int height and
+ * create a bounding box returned as a BitmapImageSizing object with
+ * consistent scale, width, height fields.
+ *
+ * @param scaleS
+ * @param widthS
+ * @param heightS
+ * @return BitmapImageSizing
+ */
+ public static BitmapImageSizing parseScaleWidthHeightStrings(
+ String scaleS, String widthS, String heightS)
+ {
+ float scale = 0.0f;
+ int width = 0;
+ int height = 0;
+
+ if (scaleS != null)
+ {
+ try
+ {
+ scale = Float.parseFloat(scaleS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand scale '" + scaleS
+ + "', won't be used.");
+ }
+ }
+ if (widthS != null)
+ {
+ try
+ {
+ width = Integer.parseInt(widthS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand width '" + widthS
+ + "', won't be used.");
+ }
+ }
+ if (heightS != null)
+ {
+ try
+ {
+ height = Integer.parseInt(heightS);
+ } catch (NumberFormatException e)
+ {
+ Console.warn("Did not understand height '" + heightS
+ + "', won't be used.");
+ }
+ }
+
+ return new BitmapImageSizing(scale, width, height);
+ }