Printing to a bitmap

Posted by: lambchop4697 on 8 September 2017, 2:34 pm EST

  • Posted 8 September 2017, 2:34 pm EST

    <P>I am trying to print a series of pages from within the spread to bitmap images instead.  I need to track each page as it is generated and then store it as a bitmap image instead of a pdf or printed document.  Is this possible?  If so, how?</P>
    <P> </P>
  • Replied 8 September 2017, 2:34 pm EST

    <P>To further clarify, I am looking to print only the bitmap of the sheet, not the print document itself.  So I just need to return the printed image of the sheet region (i.e. group of cells or grid print page) that is getting printed.  Hope this is feasible as it is an important component to being able to switch to the FarPoint control.</P>
    <P>Thanks again for any feedback!  </P>
  • Replied 8 September 2017, 2:34 pm EST

    <p>Hello,</p><p>I would like you to know that it would not be possible enhance the quality further, however I have entered a feature request to enhance the quality of the image, for the future implementations of Spread, the request id for the same is <span class="dlgtitle">99924138</span><span class="lockmsg">.</span></p><p>Thanks,</p><p>Manpreet Kaur. <br></p>
  • Replied 8 September 2017, 2:34 pm EST

    <p>Hi</p><p> </p><p>I already tested the code suggested, but the quality is low yet. </p><p>In the bitmap the resolution of the grid is too low</p><p> </p><p>Regards <br></p>
  • Replied 8 September 2017, 2:34 pm EST

    <P>You can try uisng the different properties of the Graphics class and the parameters passed to the Save method of the Bitmap class as they are provided to enhance the quality of the bitmap. I have experimented with some of them, and they make the image look better. Here is the code I have used to experiment:</P>
    <P>       public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)<BR>        {<BR>            bool functionReturnValue = false;<BR>            try<BR>            {<BR>                Bitmap bmp = new Bitmap(rect.Width, rect.Height);<BR>                Graphics g = Graphics.FromImage(bmp);<BR>                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;<BR>                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;<BR>                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;<BR>                <BR>                FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();<BR>                pi.RowStart = fpSpread1.GetViewportTopRow(0);<BR>                pi.RowEnd = fpSpread1.GetViewportBottomRow(0);<BR>                pi.ColStart = fpSpread1.GetViewportLeftColumn(0);<BR>                pi.ColEnd = fpSpread1.GetViewportRightColumn(0);<BR>                pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;<BR>                pi.UseMax = false;<BR>                fpSpread1.Sheets[0].PrintInfo = pi;<BR>                fpSpread1.OwnerPrintDraw(g, rect, 0, 1);<BR>                g.Dispose();</P>
    <P>                System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1];<BR>                System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);<BR>                eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);<BR>                bmp.Save(Destination, codec,eParams);<BR>                functionReturnValue = true;<BR>                return functionReturnValue;<BR>            }<BR>            catch (Exception err)<BR>            {<BR>                MessageBox.Show("Error number: " + err.Message);<BR>                functionReturnValue = false;<BR>            }<BR>            return functionReturnValue;<BR>        }</P>
    <P>        private void button1_Click(object sender, EventArgs e)<BR>        {<BR>            Capture_Desktop("C:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width, fpSpread1.Height));<BR>        }</P>
    <P>If it is not very compulsory to save the Bitmap to a jpeg image, so you can even try saving the image to png format in the Save method of the Bitmap class, even it enhances the quality of the image. The line of code used for same would be:</P>
    <P>                    bmp.Save(Destination, System.Drawing.Imaging.ImageFormat.Png);</P>
    <P>Hope it will help you. Please let me know if you have any queries further.</P>
    <P>Manpreet Kaur.<FONT size=2 face=Consolas><FONT size=2 face=Consolas></P></FONT></FONT>
  • Replied 8 September 2017, 2:34 pm EST

    <p>Hi Reeva</p><p> Please, do you know how can I increase the quality of the bitmap?</p><p> </p><p>Regards</p><p>Sebastiano <br></p>
  • Replied 8 September 2017, 2:34 pm EST

    very nice... thank you!
  • Replied 8 September 2017, 2:34 pm EST

    <p>Hello,</p><p>Here is code to use the OwnerPrintDraw method of the Spread to output the Spread as an bitmap image.<br></p><blockquote><p>        public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)<br>        {<br>            bool functionReturnValue = false;<br>            try<br>            {<br>                Bitmap bmp = new Bitmap(rect.Width, rect.Height);<br>                Graphics g = Graphics.FromImage(bmp);<br>                FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();<br>                pi.RowStart = fpSpread1.GetViewportTopRow(0);<br>                pi.RowEnd = fpSpread1.GetViewportBottomRow(0);<br>                pi.ColStart = fpSpread1.GetViewportLeftColumn(0);<br>                pi.ColEnd = fpSpread1.GetViewportRightColumn(0);<br>                pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;<br>                pi.UseMax = false;<br>                fpSpread1.Sheets[0].PrintInfo = pi;<br>                fpSpread1.OwnerPrintDraw(g, rect, 0, 1);<br>                g.Dispose();<br>                bmp.Save(Destination, System.Drawing.Imaging.ImageFormat.Jpeg);<br>                functionReturnValue = true;<br>                return functionReturnValue;<br>            }<br>            catch (Exception err)<br>            {<br>                MessageBox.Show("Error number: " + err.Message);<br>                functionReturnValue = false;<br>            }<br>            return functionReturnValue;<br>        }<br><br>        private void button2_Click(object sender, EventArgs e)<br>        {<br>            Capture_Desktop("d:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width, fpSpread1.Height));<br>        } </p></blockquote><p>Hope this will help you. Thanks. <br></p>
  • Replied 8 September 2017, 2:34 pm EST

    <div>Hello,</div><div> </div><div>We have checked this bug and found that we can use this code to improve/ enhance the quality of the rendering.  </div><div> </div><div>Here is the code used:- <br></div><blockquote><p style="margin:0px;">private void button1_Click(object sender, EventArgs e)</p><p style="margin:0px;"> {</p><p style="margin:0px;"> Capture_Desktop("C:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width * 4, fpSpread1.Height * 4));</p><p style="margin:0px;"> }</p><p style="margin:0px;"> public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)</p><p style="margin:0px;"> {</p><p style="margin:0px;"> bool functionReturnValue = false;</p><p style="margin:0px;"> try</p><p style="margin:0px;"> {</p><p style="margin:0px;"> Bitmap bmp = new Bitmap(rect.Width, rect.Height);</p><p style="margin:0px;"> </p><p style="margin:0px;"> Graphics g = Graphics.FromImage(bmp);</p><p style="margin:0px;"> g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;</p><p style="margin:0px;"> g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;</p><p style="margin:0px;"> g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;</p><p style="margin:0px;"> FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();</p><p style="margin:0px;"> pi.RowStart = fpSpread1.GetViewportTopRow(0);</p><p style="margin:0px;"> pi.RowEnd = fpSpread1.GetViewportBottomRow(0);</p><p style="margin:0px;"> pi.ColStart = fpSpread1.GetViewportLeftColumn(0);</p><p style="margin:0px;"> pi.ColEnd = fpSpread1.GetViewportRightColumn(0);</p><p style="margin:0px;"> pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;</p><p style="margin:0px;"> pi.UseMax = false;</p><p style="margin:0px;"> pi.ZoomFactor = 4;</p><p style="margin:0px;"> fpSpread1.Sheets[0].PrintInfo = pi;</p><p style="margin:0px;"> fpSpread1.OwnerPrintDraw(g, rect, 0, 1);</p><p style="margin:0px;"> g.Dispose();</p><p style="margin:0px;"> System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1];</p><p style="margin:0px;"> System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);</p><p style="margin:0px;"> eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);</p><p style="margin:0px;"> bmp.Save(Destination, codec, eParams);</p><p style="margin:0px;"> functionReturnValue = true;</p><p style="margin:0px;"> return functionReturnValue;</p><p style="margin:0px;"> }</p><p style="margin:0px;"> catch (Exception err)</p><p style="margin:0px;"> {</p><p style="margin:0px;"> MessageBox.Show("Error number: " + err.Message);</p><p style="margin:0px;"> functionReturnValue = false;</p><p style="margin:0px;"> }</p><p style="margin:0px;"> return functionReturnValue;</p><p style="margin:0px;"> }</p></blockquote><p style="margin:0px;">Hope  it helps.</p><p style="margin:0px;"> </p><p style="margin:0px;">Thanks,</p><p style="margin:0px;">Reeva <br></p>
  • Replied 8 September 2017, 2:34 pm EST


    I couldn't find any way to create image using console application because Spread has to be rendered on screen for capturing its bitmap image.

    Hence, we regret the inconvenience.

  • Replied 8 September 2017, 2:34 pm EST

    Reeva's code is s great solution to print as a image. I can use her code to print the spread display as a image in a windows form application. Then I face a challenge like this:
    I need to run a program to save the spread display as image files automatically on windows schedule task. Windows form application is not allowed on windows schedule task. I want to save the image files automatically without user interaction, Can the spread control be used in a console application to make this happen?
  • Replied 8 September 2017, 2:34 pm EST

    <BLOCKQUOTE><div><img src="/wp-content/uploads/CS_images/icon-quote.gif"> sebyweb:</div><div><p>Hi Reeva</p><p> Please, do you know how can I increase the quality of the bitmap?</p><p> </p><p>Regards</p><p>Sebastiano <br></p><p></div></BLOCKQUOTE></p><p>You can increase the quality of bitmap easily by using multiple properties or either have a search on Google you will get solution!</p><p>Cheap Clear Vinyl Stickers </p><p>Car Window Decal Stickers <br></p>
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels