none
Converting windows form to bmp - image crops when the screen resolution is changed

    Question

  • I am converting windows form to a bitmap file using   DrawToBitmap method.  My code looks like this.

                Dim wid As Integer = 760 '  Me.Width
                Dim hgt As Integer = 780 ' Me.Height
                Dim bm As New Bitmap(wid, hgt)
                Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
                bm.Save(CurDir() & "\sample.bmp")

    This code work fine on desktop/laptop with the screen resolution 1024 x 768  or above.   If I use app on a table pc – with the screen resolution is 800 x 480, the image gets cropped. 
    Any suggestion or alternate mode.

    Thanks

    Thursday, October 14, 2010 2:36 PM

All replies

  • i m giving you the c sharp code

     

    Bitmap bi = new Bitmap(this.Width, this.Height);
     this.DrawToBitmap(bi,new Rectangle(0,0,this.Width,this.Height));
     bi.Save (@"c:\Test.bmp", ImageFormat.Bmp); 

     

    use this or convert it in to VB

    Thursday, October 14, 2010 2:45 PM
  • NO THIS CODE WON'T WORK, MY CODE IS SIMILAR  TO YOUR CODE,  I HAD GIVEN ABSOLUTE VALUE OF WIDTH  & HEIGHT, I ALSO TRIED WITH ME.WIDTH & ME.HEIGHT

    Thursday, October 14, 2010 3:17 PM
  • Hi ravi5r4,

     

    Can the issue only be repro on tablet pc? I have tried both your and techmania’s code. Techmania’s code can capture the whole form’s picture no matter which size it use. You code use absolute value so it can only capture a picture with 760 X 780. When the form is larger than that size, the image outside the 760 X 780 cannot be captured.

     

    If you mean it can only be repro on tablet pc, I will ask other engineers for help.

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Friday, October 15, 2010 8:15 AM
  • rightly said moderator sir  :)
    Friday, October 15, 2010 11:48 AM
  • the problem is with tablet pc  where  the screen resolution  800 x 480.  Other wise it works fine on a higher resolution system say 1024 x 768 or above.

     

    Thanks

    Monday, October 18, 2010 5:21 PM
  • I am converting windows form to a bitmap file using   DrawToBitmap method.  My code looks like this.

                Dim wid As Integer = 760 '  Me.Width
                Dim hgt As Integer = 780 ' Me.Height
                Dim bm As New Bitmap(wid, hgt)
                Me.DrawToBitmap(bm, New Rectangle(0, 0, wid, hgt))
                bm.Save(CurDir() & "\sample.bmp")

    This code work fine on desktop/laptop with the screen resolution 1024 x 768  or above.   If I use app on a table pc – with the screen resolution is 800 x 480, the image gets cropped. 
    Any suggestion or alternate mode.

    Thanks

     

    The problem is not DrawToBitmap. You will notice that the form that you are capturing itself is already cropped because the height resolution of the tablet PC is smaller.

    Monday, October 18, 2010 10:23 PM
  • Hi,

    I don't think the problem is very clear to us - since we can't see what exactly the problem is.

    Could you please take a screenshot of your TabletPC at the time you're going to save the form to bitmap, and upload the screenshot together with the resulting bitmap to SkyDrive so we can take a look?

    Thanks,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    Tuesday, October 19, 2010 3:02 AM