Use Java to create WMF image files
Enhance the capabilities of your Java applications by handling WMF vector image files
Download Free TrialHow to Create WMF Image File Using Java
Discover the ease of creating WMF vector image files using Java. This guide offers essential insights and guidance suitable for developers of all levels. Explore the seamless integration steps for creating WMF images, enhancing your programming proficiency. Utilize the Aspose.Drawing for Java library, renowned for its feature-rich, powerful, and user-friendly 2D graphics drawing API for the Java platform. Access the latest version directly from Maven repository and incorporate it into your Maven-based project by applying the specified configurations to the pom.xml file.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-drawing</artifactId>
<version>version of aspose-drawing API</version>
<classifier>jdk18</classifier>
</dependency>
Steps to Create WMF via Java
You need the aspose-drawing-version-jdk18.jar to try the following workflow in your own environment.
- Create Memory steam object.
- Create metafile object using Metafile class.
- Create graphics object using Graphics.FromImage() method.
- Draw graphic elements.
- Write data to WMF file format.
System Requirements
Aspose.Drawing for Java is supported on all major operating systems. Just make sure that you have the following prerequisites.
- JDK 1.8 or higher is installed.
Create WMF Image File - Java
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA | |
import com.aspose.drawing.Graphics; | |
import com.aspose.drawing.Pens; | |
import com.aspose.drawing.imaging.Metafile; | |
import com.aspose.drawing.system.io.MemoryStream; | |
public class SaveWmf { | |
public static void main(String[] args) { | |
MemoryStream ms = new MemoryStream(); | |
try { | |
Metafile metafile = new Metafile(ms, 1); | |
try { | |
Graphics graphics = Graphics.fromImage(metafile); | |
graphics.drawLine(Pens.getRed(), 10, 10, 50, 50); | |
} finally { | |
metafile.dispose(); | |
} | |
} finally { | |
ms.dispose(); | |
} | |
FileOutputStream fos = null; | |
try { | |
fos = new FileOutputStream("out.wmf"); | |
byte[] array = ms.toArray(); | |
fos.write(array); | |
fos.close(); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
About Aspose.Drawing for Java API
Aspose.Drawing serves as a fully managed, cross-platform 2D graphic library, facilitating the creation of text, geometries, and images. Its cross-platform Java-compatible API enables effortless integration across diverse operating systems with Java installed. Engineered against Java 8, Aspose.Drawing finds applications in Web, Mobile, Desktop, and Cloud environments. The drawing engine empowers users to render vector graphics, encompassing lines, curves, and figures, alongside text in multiple fonts, sizes, and styles onto vector or raster images in prevalent graphics file formats. This rendering capability, integral to Aspose.Drawing fosters seamless integration and compatibility with a wide array of commonly used graphics file formats.WMF What is WMF File Format
Files with the .WMF extension serves as a container for storing both vector and bitmap-format image data. Specifically, WMF belongs to the vector file format category within Graphics file formats, offering device-independent representation. This format provides versatility in storing graphical data, supporting a wide range of applications and platforms.
Read More