How to add symbol image to arcScene using local .png or .img file?
I used this code but it doesnt work:
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
sceneView.getGraphicsOverlays().add(graphicsOverlay);
// An image file on the hard drive.
File file = new File("C:\\Users\\user\\Documents\\IMG1.jpg");
String localUri = file.toURI().toString();
PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(localUri);
markerSymbol.setHeight(100);
markerSymbol.setWidth(100);
markerSymbol.loadAsync();
com.esri.arcgisruntime.geometry.Point symbolPoint = new com.esri.arcgisruntime.geometry.Point(20, 20, SpatialReferences.getWgs84());
Graphic symbolGraphic = new Graphic(symbolPoint, markerSymbol);
markerSymbol.addDoneLoadingListener(() -> graphicsOverlay.getGraphics().add(symbolGraphic));
Solved! Go to Solution.
If you are working with a file on the local OS, you don't need a full URI format, you can just use the file on its own.
I just tried this out with the following code:
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
// An image file on the hard drive.
PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol("./FireStation.png");
markerSymbol.setHeight(100);
markerSymbol.setWidth(100);
markerSymbol.loadAsync();
markerSymbol.addDoneLoadingListener(() -> {
System.out.println("loaded status " + markerSymbol.getLoadStatus());
if (markerSymbol.getLoadStatus() == LoadStatus.LOADED) {
// use the symbol
Point point = new Point(0,0);
Graphic graphic = new Graphic(point,markerSymbol);
graphicsOverlay.getGraphics().add(graphic);
} else {
// error state as it didn't load
System.out.println("Failed to load: " + markerSymbol.getLoadError().getCause());
}
});
Does this work for you?
If you are working with a file on the local OS, you don't need a full URI format, you can just use the file on its own.
I just tried this out with the following code:
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
// An image file on the hard drive.
PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol("./FireStation.png");
markerSymbol.setHeight(100);
markerSymbol.setWidth(100);
markerSymbol.loadAsync();
markerSymbol.addDoneLoadingListener(() -> {
System.out.println("loaded status " + markerSymbol.getLoadStatus());
if (markerSymbol.getLoadStatus() == LoadStatus.LOADED) {
// use the symbol
Point point = new Point(0,0);
Graphic graphic = new Graphic(point,markerSymbol);
graphicsOverlay.getGraphics().add(graphic);
} else {
// error state as it didn't load
System.out.println("Failed to load: " + markerSymbol.getLoadError().getCause());
}
});
Does this work for you?
Thank you! It works.
An alternative solution would be to construct the symbol directly from a JavaFX image. If you are already using the image elsewhere in your app for example, you could do this:
Image image = new Image("file:FireStation.png", 100, 100, false, false);
PictureMarkerSymbol markerSymbol = new PictureMarkerSymbol(image);