• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting WMF(Windows Meta File) to JPEG

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic