Printing to a bitmap

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

  • Posted 8 September 2017, 2:34 pm EST

    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?


     

  • Replied 8 September 2017, 2:34 pm EST

    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.


    Thanks again for any feedback! 

  • Replied 8 September 2017, 2:34 pm EST

    Hello,

    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 99924138.

    Thanks,

    Manpreet Kaur.

  • Replied 8 September 2017, 2:34 pm EST

    Hi

     

    I already tested the code suggested, but the quality is low yet.

    In the bitmap the resolution of the grid is too low

     

    Regards

  • Replied 8 September 2017, 2:34 pm EST

    Hello,


    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:


           public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)
            {
                bool functionReturnValue = false;
                try
                {
                    Bitmap bmp = new Bitmap(rect.Width, rect.Height);
                    Graphics g = Graphics.FromImage(bmp);
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                   
                    FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();
                    pi.RowStart = fpSpread1.GetViewportTopRow(0);
                    pi.RowEnd = fpSpread1.GetViewportBottomRow(0);
                    pi.ColStart = fpSpread1.GetViewportLeftColumn(0);
                    pi.ColEnd = fpSpread1.GetViewportRightColumn(0);
                    pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;
                    pi.UseMax = false;
                    fpSpread1.Sheets[0].PrintInfo = pi;
                    fpSpread1.OwnerPrintDraw(g, rect, 0, 1);
                    g.Dispose();


                    System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1];
                    System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);
                    eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
                    bmp.Save(Destination, codec,eParams);
                    functionReturnValue = true;
                    return functionReturnValue;
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error number: " + err.Message);
                    functionReturnValue = false;
                }
                return functionReturnValue;
            }


            private void button1_Click(object sender, EventArgs e)
            {
                Capture_Desktop("C:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width, fpSpread1.Height));
            }


    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:


                        bmp.Save(Destination, System.Drawing.Imaging.ImageFormat.Png);


    Hope it will help you. Please let me know if you have any queries further.


    Thanks,


    Manpreet Kaur.

  • Replied 8 September 2017, 2:34 pm EST

    Hi Reeva

     Please, do you know how can I increase the quality of the bitmap?

     

    Regards

    Sebastiano

  • Replied 8 September 2017, 2:34 pm EST

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

    Hello,

    Here is code to use the OwnerPrintDraw method of the Spread to output the Spread as an bitmap image.

            public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)
            {
                bool functionReturnValue = false;
                try
                {
                    Bitmap bmp = new Bitmap(rect.Width, rect.Height);
                    Graphics g = Graphics.FromImage(bmp);
                    FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();
                    pi.RowStart = fpSpread1.GetViewportTopRow(0);
                    pi.RowEnd = fpSpread1.GetViewportBottomRow(0);
                    pi.ColStart = fpSpread1.GetViewportLeftColumn(0);
                    pi.ColEnd = fpSpread1.GetViewportRightColumn(0);
                    pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;
                    pi.UseMax = false;
                    fpSpread1.Sheets[0].PrintInfo = pi;
                    fpSpread1.OwnerPrintDraw(g, rect, 0, 1);
                    g.Dispose();
                    bmp.Save(Destination, System.Drawing.Imaging.ImageFormat.Jpeg);
                    functionReturnValue = true;
                    return functionReturnValue;
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error number: " + err.Message);
                    functionReturnValue = false;
                }
                return functionReturnValue;
            }

            private void button2_Click(object sender, EventArgs e)
            {
                Capture_Desktop("d:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width, fpSpread1.Height));
            }

    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:34 pm EST

    Hello,
     
    We have checked this bug and found that we can use this code to improve/ enhance the quality of the rendering. 
     
    Here is the code used:-

    private void button1_Click(object sender, EventArgs e)

    {

    Capture_Desktop("C:\\test.jpg", new Rectangle(0, 0, fpSpread1.Width * 4, fpSpread1.Height * 4));

    }

    public bool Capture_Desktop(string Destination, System.Drawing.Rectangle rect)

    {

    bool functionReturnValue = false;

    try

    {

    Bitmap bmp = new Bitmap(rect.Width, rect.Height);

    Graphics g = Graphics.FromImage(bmp);

    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

    FarPoint.Win.Spread.PrintInfo pi = new FarPoint.Win.Spread.PrintInfo();

    pi.RowStart = fpSpread1.GetViewportTopRow(0);

    pi.RowEnd = fpSpread1.GetViewportBottomRow(0);

    pi.ColStart = fpSpread1.GetViewportLeftColumn(0);

    pi.ColEnd = fpSpread1.GetViewportRightColumn(0);

    pi.PrintType = FarPoint.Win.Spread.PrintType.CellRange;

    pi.UseMax = false;

    pi.ZoomFactor = 4;

    fpSpread1.Sheets[0].PrintInfo = pi;

    fpSpread1.OwnerPrintDraw(g, rect, 0, 1);

    g.Dispose();

    System.Drawing.Imaging.ImageCodecInfo codec = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[1];

    System.Drawing.Imaging.EncoderParameters eParams = new System.Drawing.Imaging.EncoderParameters(1);

    eParams.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);

    bmp.Save(Destination, codec, eParams);

    functionReturnValue = true;

    return functionReturnValue;

    }

    catch (Exception err)

    {

    MessageBox.Show("Error number: " + err.Message);

    functionReturnValue = false;

    }

    return functionReturnValue;

    }

    Hope  it helps.

     

    Thanks,

    Reeva

  • Replied 8 September 2017, 2:34 pm EST

    Hello,

    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.

    Thanks,
    Reeva
  • 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 vb.net 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

    sebyweb:

    Hi Reeva

     Please, do you know how can I increase the quality of the bitmap?

     

    Regards

    Sebastiano

    You can increase the quality of bitmap easily by using multiple properties or either have a search on Google you will get solution!

    Cheap Clear Vinyl Stickers

    Car Window Decal Stickers

Need extra support?

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

Learn More

Forum Channels