@Override protected Image loadImage(String path, ImageReceiver<Bitmap> recv) { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { InputStream is = openAsset(rsrc.path); try { BitmapOptions options = createOptions(path, true, rsrc.scale); return recv.imageLoaded(BitmapFactory.decodeStream(is, null, options), options.scale); } 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 } } platform.log().warn("Could not load image: " + pathPrefix + path, error); return recv.loadFailed(error != null ? error : new FileNotFoundException(path)); }
@Override protected Image loadImage(String path, ImageReceiver<Bitmap> recv) { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(path)) { try { InputStream is = openAsset(rsrc.path); try { BitmapOptions options = createOptions(path, true, rsrc.scale); return recv.imageLoaded(BitmapFactory.decodeStream(is, null, options), options.scale); } 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 } } platform.log().warn("Could not load image: " + pathPrefix + path, error); return recv.loadFailed(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)) { float[] size = imageManifest.imageSize(rsrc.path); if (size == null) continue; // try other scales HtmlImage image = getImage(rsrc.path, rsrc.scale); image.img.setWidth(MathUtil.iceil(size[0])); image.img.setHeight(MathUtil.iceil(size[1])); return image; } return createErrorImage(new Throwable("Image missing from manifest: " + path)); } }
@Override protected Image loadImage(String path, ImageReceiver<UIImage> recv) { Throwable error = null; for (Scale.ScaledResource rsrc : platform.graphics().ctx().scale.getScaledResources(path)) { File fullPath = resolvePath(rsrc.path); if (!fullPath.exists()) continue; // platform.log().debug("Loading image: " + fullPath); UIImage img = new UIImage(fullPath); if (img != null) return recv.imageLoaded(img, rsrc.scale); // 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 platform.log().warn("Failed to load image '" + fullPath + "'."); error = new Exception("Failed to load " + fullPath); } if (error == null) { File fullPath = resolvePath(path); platform.log().warn("Missing image '" + fullPath + "'."); error = new FileNotFoundException(fullPath.toString()); } return recv.loadFailed(error); }
@Override protected Image loadImage(String fullPath, ImageReceiver<BufferedImage> recv) { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(fullPath)) { try { BufferedImage image = requireResource(rsrc.path).readImage();
@Override protected Image loadImage(String fullPath, ImageReceiver<BufferedImage> recv) { Exception error = null; for (Scale.ScaledResource rsrc : assetScale().getScaledResources(fullPath)) { try { BufferedImage image = requireResource(rsrc.path).readImage();