use of com.android.tools.pixelprobe.Image in project android by JetBrains.
the class LayeredImageConverter method toVectorDrawableXml.
/**
* Loads the specified file as a pixelprobe {@link Image}, finds its vector layers
* and converts them to a Vector Drawable XML representation.
*
* @param path The file to convert to Vector Drawable
* @return The XML representation of a Vector Drawable
*
* @throws IOException If an error occur while parsing the file
*/
@NotNull
String toVectorDrawableXml(@NotNull File path) throws IOException {
FileInputStream in = new FileInputStream(path);
Image image = PixelProbe.probe(in, new Decoder.Options().decodeLayerImageData(false).decodeLayerTextData(false).decodeLayerAdjustmentData(false).decodeGuides(false));
Rectangle2D.Double bounds = new Rectangle2D.Double(0.0, 0.0, image.getWidth(), image.getHeight());
myFormat = createDecimalFormat((float) bounds.getWidth(), (float) bounds.getHeight());
Element vector = new Element(SdkConstants.TAG_VECTOR);
extractPathLayers(vector, image.getLayers());
vector.attribute("width", String.valueOf((int) bounds.getWidth()) + "dp").attribute("height", String.valueOf((int) bounds.getHeight()) + "dp").attribute("viewportWidth", String.valueOf((int) bounds.getWidth())).attribute("viewportHeight", String.valueOf((int) bounds.getHeight()));
String xml = toVectorDrawable(vector);
in.close();
return xml;
}
use of com.android.tools.pixelprobe.Image in project android by JetBrains.
the class FileChooserActionListener method openDeviceChoiceDialog.
/**
* Open a dialog asking to choose a device whose dimensions match those of the image
*/
private static void openDeviceChoiceDialog(VirtualFile virtualFile, @NotNull NlProperty fileProperty, @Nullable NlProperty cropProperty) {
if (virtualFile.exists() && !virtualFile.isDirectory()) {
try {
final Image probe = PixelProbe.probe(virtualFile.getInputStream());
final BufferedImage image = probe.getMergedImage();
if (image == null) {
return;
}
final NlModel model = fileProperty.getModel();
final Configuration configuration = model.getConfiguration();
final Device device = configuration.getDevice();
if (device == null) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
final DeviceSelectionPopup deviceSelectionPopup = new DeviceSelectionPopup(model.getProject(), configuration, image);
if (deviceSelectionPopup.showAndGet()) {
saveMockupFile(virtualFile, fileProperty, cropProperty);
}
});
} catch (IOException e1) {
LOGGER.warn("Unable to open this file\n" + e1.getMessage());
}
}
}
use of com.android.tools.pixelprobe.Image in project android by JetBrains.
the class MockupFileHelper method openImageFile.
@Nullable
public static Image openImageFile(String path) {
Image image = null;
final File file = new File(path);
if (!file.exists()) {
return null;
}
if (IMAGE_CACHE.containsKey(path)) {
return IMAGE_CACHE.get(path);
}
try (FileInputStream in = new FileInputStream(file)) {
image = PixelProbe.probe(in, Decoder.Options.LAYER_METADATA_ONLY);
IMAGE_CACHE.put(path, image);
} catch (IOException e) {
Logger.getInstance(MockupLayer.class).error(e);
}
return image;
}
Aggregations