public static ResourceBitmap createBitmap(GraphicFactory graphicFactory, DisplayModel displayModel, String relativePathPrefix, String src, int width, int height, int percent) throws IOException { if (src == null || src.length() == 0) { // no image source defined return null; } InputStream inputStream = createInputStream(graphicFactory, relativePathPrefix, src); try { String absoluteName = getAbsoluteName(relativePathPrefix, src); // we need to hash with the width/height included as the same symbol could be required // in a different size and must be cached with a size-specific hash int hash = new StringBuilder().append(absoluteName).append(width).append(height).append(percent).toString().hashCode(); if (src.toLowerCase(Locale.ENGLISH).endsWith(".svg")) { try { return graphicFactory.renderSvg(inputStream, displayModel.getScaleFactor(), width, height, percent, hash); } catch (IOException e) { throw new IOException("SVG render failed " + src, e); } } try { return graphicFactory.createResourceBitmap(inputStream, displayModel.getScaleFactor(), width, height, percent, hash); } catch (IOException e) { throw new IOException("Reading bitmap file failed " + src, e); } } finally { inputStream.close(); } }
public static ResourceBitmap createBitmap(GraphicFactory graphicFactory, DisplayModel displayModel, String relativePathPrefix, String src, int width, int height, int percent) throws IOException { if (src == null || src.length() == 0) { // no image source defined return null; } InputStream inputStream = createInputStream(graphicFactory, relativePathPrefix, src); try { String absoluteName = getAbsoluteName(relativePathPrefix, src); // we need to hash with the width/height included as the same symbol could be required // in a different size and must be cached with a size-specific hash int hash = new StringBuilder().append(absoluteName).append(width).append(height).append(percent).toString().hashCode(); if (src.toLowerCase(Locale.ENGLISH).endsWith(".svg")) { try { return graphicFactory.renderSvg(inputStream, displayModel.getScaleFactor(), width, height, percent, hash); } catch (IOException e) { throw new IOException("SVG render failed " + src, e); } } try { return graphicFactory.createResourceBitmap(inputStream, absoluteName.hashCode()); } catch (IOException e) { throw new IOException("Reading bitmap file failed " + src, e); } } finally { inputStream.close(); } }
markerIcon = GRAPHIC_FACTORY.createResourceBitmap(MapsforgeMapView.class.getResourceAsStream("marker.png"), -1); waypointIcon = GRAPHIC_FACTORY.createResourceBitmap(MapsforgeMapView.class.getResourceAsStream("waypoint.png"), -1); } catch (IOException e) { log.severe("Cannot create marker and waypoint icon: " + e);