aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes converting WMF(Windows Meta File)  to JPEG Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "converting WMF(Windows Meta File)  to JPEG" Watch "converting WMF(Windows Meta File)  to JPEG" New topic
Author

converting WMF(Windows Meta File) to JPEG

madhu nelanti
Greenhorn

Joined: Jan 06, 2007
Posts: 2
hi.,

I have a problem in converting wmf to jpeg so,please help me to read and convert a .wmf (Windows MetaFile) and .emf(Enhanced MetaFile's) to jpeg or bmp images.please help me with code.
Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
The Apache Batik project includes code to convert WMF to SVG. There may be other libraries that can create a bitmap image from SVG.

There's also a commercial library from Aspose that can handle these file formats.
Roshnikanta Sharma
Greenhorn

Joined: Dec 26, 2008
Posts: 6
Thank you Sir,
Please suggest me some of the jar which will be availabale as opensource project. I have tried with BATIK . Is there any other jar(api) which would serve the purpose for converting wmf(window metafile) to jpg or other image formats


With regards, B Roshnikanta Sharma
Roshnikanta Sharma
Greenhorn

Joined: Dec 26, 2008
Posts: 6
What I have done using BATIK is as follows
---------------------------------
public static void main(String[] a)
{
String wmfPath="F:\\images\\image4.wmf";
FileOutputStream awmfPath=new FileOutputStream("F:mages\\a4.wmf");
File wmf=new File(wmfPath);
FileInputStream wmfStream=new FileInputStream(wmf);
ByteArrayOutputStream imageOut=new ByteArrayOutputStream();
byte[]buffer=new byte[1024*1024];
int noOfByteRead=0;
while((noOfByteRead=wmfStream.read())!=-1)
{
imageOut.write(noOfByteRead);
awmfPath.write(noOfByteRead);
}
imageOut.flush();
awmfPath.flush();
WMFTranscoder transcoder = new WMFTranscoder();
TranscodingHints hints=new TranscodingHints();
hints.put(WMFTranscoder.KEY_HEIGHT,2000f);
hints.put(WMFTranscoder.KEY_WIDTH,2000f);
transcoder.setTranscodingHints(hints);
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(imageOut.toByteArray()));
ByteArrayOutputStream svg = new ByteArrayOutputStream();
TranscoderOutput output = new TranscoderOutput(svg);

transcoder.transcode(input, output);
String svgFile=StringUtils.replace(wmfPath,"wmf","svg");
FileOutputStream fileOut=new FileOutputStream(svgFile);
fileOut.write(svg.toByteArray());
fileOut.flush();
// svg -> jpg
ImageTranscoder it = new JPGTranscoder();
ByteArrayOutputStream jpg = new ByteArrayOutputStream();
it.transcode(new TranscoderInput(new
ByteArrayInputStream(svg.toByteArray())), new TranscoderOutput(jpg));
String jpgFile=StringUtils.replace(wmfPath,"wmf","jpg");
FileOutputStream jpgOut=new FileOutputStream(jpgFile);
jpgOut.write(jpg.toByteArray());
jpgOut.flush();
}
-------------------------------
But the generated image is scaled up so hugely.
Did I do something wrong, PLease help me out.
And dplease suggest me some other alternatives.
Any help and suggestions would be highly appreciative.
Thanking you in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
I suppose the size of the JPEG depends on the settings of the original image. If there are no control parameters for this one can use during the conversion, then you can always use Java graphics to scale the image down (Read it into a BufferedImage, draw it scaled down into a second BufferedImage, save it to disk. The javax.imageio.ImageIO class can read and write JPEGs from/to disk.)
Roshnikanta Sharma
Greenhorn

Joined: Dec 26, 2008
Posts: 6
Thank you Ulf Dittmer,
Please provide me code by rectifying the above code snippet.
I have been stuck to this issue for nearly a week.

With regards,
B Roshnikanta Sharma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: converting WMF(Windows Meta File) to JPEG