Print Page | Close Window

C# - Using AddImageFromString with Drawing.Imaging

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2308
Printed Date: 04 May 24 at 7:15PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: C# - Using AddImageFromString with Drawing.Imaging
Posted By: AndrewC
Subject: C# - Using AddImageFromString with Drawing.Imaging
Date Posted: 20 Jun 12 at 12:43PM

            Bitmap bmp = new Bitmap("ThomasCook.bmp");

            // Create a memory stream and save the bitmap to it
            Stream st = new MemoryStream();
            bmp.Save(st, System.Drawing.Imaging.ImageFormat.Bmp);

            // Convert the stream to a byte[] so we can use it with AddImageFromString
            st.Position = 0;
            byte[] Buffer = new byte[st.Length];
            st.Read(Buffer, 0, (int)st.Length);
            st.Dispose();

            int id = QP.AddImageFromString(Buffer, 0);
            QP.SelectImage(id);

            QP.SetOrigin(1);

            int dpix = QP.ImageHorizontalResolution();
            int dpiy = QP.ImageVerticalResolution();

            if (dpix == 0) dpix = 96;
            if (dpiy == 0) dpiy = 96;

            int xx = QP.ImageWidth();
            int yy = QP.ImageHeight();

            double ImageWidthInPoints = (double)QP.ImageWidth() / dpix * 72.0; // assumming dpi units
            double ImageHeightInPoints = (double)QP.ImageHeight() / dpiy * 72.0;

            QP.DrawImage(0, 0, ImageWidthInPoints, ImageHeightInPoints);


            Buffer = null;
            GC.Collect();

            QP.SaveToFile("out.pdf");




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk