@Override public Image getImage (String path) { Scale assetScale = (this.assetScale == null) ? Scale.ONE : this.assetScale; List<Scale.ScaledResource> rsrcs = assetScale.getScaledResources(path); return getImage(rsrcs.get(0).path, rsrcs.get(0).scale); }
@Override public Image getImage (String path) { Scale assetScale = (this.assetScale == null) ? Scale.ONE : this.assetScale; List<Scale.ScaledResource> rsrcs = assetScale.getScaledResources(path); return getImage(rsrcs.get(0).path, rsrcs.get(0).scale); }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { InputStream is = openAsset(rsrc.path); try { BitmapOptions options = createOptions(path, true, rsrc.scale); Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); return new ImageImpl.Data(options.scale, bitmap, bitmap.getWidth(), bitmap.getHeight()); } finally { is.close(); } } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } catch (Exception e) { error = e; break; // the image was broken not missing, stop here } } plat.reportError("Could not load image: " + pathPrefix + path, error); throw error != null ? error : new FileNotFoundException(path); }
@Override public Image getImageSync(String path) { if (imageManifest == null) throw new UnsupportedOperationException( "getImageSync(" + path + ")"); else { for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { int[] size = imageManifest.imageSize(rsrc.path); if (size == null) continue; // try other scales return getImage(rsrc.path, rsrc.scale).preload(size[0], size[1]); } return new HtmlImage(plat.graphics(), new Throwable("Image missing from manifest: " + path)); } }
@Override public Image getImageSync(String path) { if (imageManifest == null) throw new UnsupportedOperationException( "getImageSync(" + path + ")"); else { for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { int[] size = imageManifest.imageSize(rsrc.path); if (size == null) continue; // try other scales return getImage(rsrc.path, rsrc.scale).preload(size[0], size[1]); } return new HtmlImage(plat.graphics(), new Throwable("Image missing from manifest: " + path)); } }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : plat.graphics().scale().getScaledResources(path)) { File fullPath = resolvePath(rsrc.path); if (!fullPath.exists()) continue; // plat.log().debug("Loading image: " + fullPath); UIImage img = UIImage.getImage(fullPath); if (img != null) return toData(rsrc.scale, img); // note this error if this is the lowest resolution image, but fall back to lower resolution // images if not; in the Java backend we'd fail here, but this is a production backend, so we // want to try to make things work plat.log().warn("Failed to load image '" + fullPath + "'."); error = new Exception("Failed to load " + fullPath); } if (error == null) { File fullPath = resolvePath(path); plat.log().warn("Missing image '" + fullPath + "'."); error = new FileNotFoundException(fullPath.toString()); } throw error; }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }
@Override protected ImageImpl.Data load (String path) throws Exception { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { BufferedImage image = requireResource(rsrc.path).readImage(); // if image is at a higher scale factor than the view, scale to the view display factor Scale viewScale = plat.graphics().scale(), imageScale = rsrc.scale; float viewImageRatio = viewScale.factor / imageScale.factor; if (viewImageRatio < 1) { image = scaleImage(image, viewImageRatio); imageScale = viewScale; } if (plat.config.convertImagesOnLoad) { BufferedImage convertedImage = JavaGraphics.convertImage(image); if (convertedImage != image) { plat.log().debug("Converted image: " + path + " [type=" + image.getType() + "]"); image = convertedImage; } } return new ImageImpl.Data(imageScale, image, image.getWidth(), image.getHeight()); } catch (FileNotFoundException fnfe) { error = fnfe; // keep going, checking for lower resolution images } } plat.log().warn("Could not load image: " + path + " [error=" + error + "]"); throw error != null ? error : new FileNotFoundException(path); }