This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting WMF(Windows Meta File) to JPEG

 
madhu nelanti
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roshnikanta Sharma
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic