word to image conversion

Technical support for Spire.Doc

Moderator: iceblue support

word to image conversion

Postby kulsumarif » Mon Jan 14, 2013 10:10 pm

I am using Spire.Doc for converting word doc to images. I am not able to set the resolution of the images being created (i.e dots per inch).


Image[] images = document.SaveToImages(Spire.Doc.Documents.ImageType.Bitmap);

When I check each image coming back, the horizontal/vertical resolution show 100.

Appreciate help..
-Kulsum
kulsumarif
 
Posts: 1
Joined: Thu Jan 03, 2013 7:28 pm

Re: word to image conversion

Postby amy.zhao » Tue Jan 15, 2013 4:04 am

Hello Kulsum,

Thanks for your inquiry.
Spire.doc don't support that setting the resolution of the images at present. We are sorry for the inconvenience.
We may add the featrue in the future. We will inform you when spire.doc can support it.

Best regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2251
Joined: Wed Jun 27, 2012 8:50 am

Re: word to image conversion

Postby amy.zhao » Mon May 27, 2013 9:13 am

Dear Kulsum,

Our Spire.doc has supported resetting the resolution of the images. Please try the code snippet below.

Code: Select all
 static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile(@"..\..\Word.doc");
            Image[] images = document.SaveToImages(ImageType.Metafile);

            for(int i=0;i<images.Length;i++)
            {
                Metafile mf =images[i] as Metafile;
                Image image = ResetResolution(mf, 300);
                image.Save(String.Format("image-{0}.png", i), ImageFormat.Png);
            }
        }

        public static Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }

            return bmp;
        }



There is any issue, please feel free to contact us.

Regards,
Amy
E-iceblue support team
User avatar
amy.zhao
 
Posts: 2251
Joined: Wed Jun 27, 2012 8:50 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests