Results 1 to 6 of 6

Thread: [RESOLVED] CaptureControl CopyFromScreen is reducing the original image width and height

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    7

    Resolved [RESOLVED] CaptureControl CopyFromScreen is reducing the original image width and height

    Hello, I hope someone out there can give me some help. What part of the program does is to take the original image and gets its image height and width and then flips the image over- much like having a physical photo in your hand and turning it over to see the backside. I figured out how to do that. I have been having problems saving the text to the image that is housed in the picturebox2, but I found a function from By Edgemeal on the forum here and it did the trick to save the image with text. The only thing is that when I use it, it reduces the size of the image. I need to find a way to maintain the original size being image width and height. Right now I start of with an image that is 640x400, I then flip the image over and the size is still 640x400, so far so good but, when I add the text to image and using the function I found to copyfromscreen it reduces the image to 474x367. I need some help here please.
    I have a screen shot that I will upload as well so that you can see what it is doing. I am also using a combin image routine but that part is not the problem.

    Name:  Clientsize_VB.net_for_help.jpg
Views: 2118
Size:  23.3 KB
    Code:
    Private Sub ButAddTextBehindPic_Click(sender As System.Object, e As System.EventArgs) Handles ButAddTextBehindPic.Click
    'Dim bimp As Bitmap
    Dim drawfont As New Font(TextBox1.Font, 0)
    Dim drawbrush As New SolidBrush(TextBox1.ForeColor)
    Dim txt = TextBox1.Text
    PictureBox2.CreateGraphics.DrawString(txt, drawfont, drawbrush, 10, 100)
    'Clipboard.SetImage(PictureBox2.Image) this will not work for what I want.....just blank white image

    ' this one works does save image with text but reduse the width and height of image
    bimp = CaptureControl(PictureBox2) ' capture pic2box area
    bimp.Save(picsave3, Imaging.ImageFormat.Jpeg) ' save to file
    PictureBox2.Image = bimp ' display in pic box
    'PictureBox2.Image = ScaleImage(Image.FromFile(picsave3), PictureBox2.Height, PictureBox2.Width) this has no effect :-(

    TextImgAfter.Text = ClientSize.Height ' shows 637 but on hard disk shows 367 for height
    TextImageafterAdTxt.Text = ClientSize.Width ' shows 1267 (sometimes 1157) but on hard disk shows 474 for width
    Dim dpiX As Single = PictureBox1.Image.HorizontalResolution
    Dim dpiY As Single = PictureBox1.Image.VerticalResolution
    TextHorzDPIafter.Text = dpiX
    TextVertDPIafter.Text = dpiY
    End Sub

    Edit part of post:
    the function I found:
    Private Shared Function CaptureControl(ByVal control As Control) As Bitmap
    Dim bmp As Bitmap = New Bitmap(control.ClientSize.Width, control.ClientSize.Height)
    Using gr As Graphics = Graphics.FromImage(bmp)
    gr.CopyFromScreen(control.PointToScreen(control.ClientRectangle.Location), Point.Empty, control.ClientSize)
    End Using
    Return bmp
    End Function
    Name:  Details_of_image.jpg
Views: 1641
Size:  39.4 KB

    The one on the left side is the original in picturebox1 the right is after using the function to capture the image. The original shows no DPI
    Last edited by marios; Apr 7th, 2015 at 02:33 PM. Reason: To add more detail to the problem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width