Click here to Skip to main content
15,843,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all i am taking print screen of my form throug coding but the problem is, its storing only the application start path, i want to set my desired destination path for storing that screen shot image, i am using the below coding for this ..

VB
Dim path As String
      clear()
      ' Dim b As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
      Dim b As Bitmap = New Bitmap(Me.Width, Me.Height, Imaging.PixelFormat.Format32bppArgb)
      Dim gfx As Graphics = Graphics.FromImage(b)
      gfx.CopyFromScreen(My.Computer.Screen.Bounds.X, My.Computer.Screen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
      path = "C:\Documents and Settings\Nano\My Documents\My Pictures"
      b.Save("my2.jpg", Imaging.ImageFormat.Jpeg)

      MsgBox("Screen Shot Taken Succecssfully", MsgBoxStyle.Information)


Thanks in advance.
Posted
Updated 29-Nov-10 6:47am
v2

1 solution

try:
VB
Dim b As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
Dim gfx As Graphics = Graphics.FromImage(b)
gfx.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)

path = "C:\Documents and Settings\Nano\My Documents\My Pictures\my2.jpg"
b.Save(path, Imaging.ImageFormat.Jpeg)


The code you posted has saved the image in the same folder as your applications executable.

Edited: Or, use this function from the web (just provide the path name):
Function ScreenToPicture(ByVal Location As String) As String
 
        Try
            Dim currentScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim ScreenToBitmap As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
            Dim gGraphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(ScreenToBitmap)
 
            gGraphics.CopyFromScreen(New Point(0, 0), New Point(0, 0), currentScreenSize)
            ScreenToBitmap.Save(Location)
 
            Return Location
 
        Catch ex As Exception
            Return ex.Message
        End Try
 
    End Function
 
Share this answer
 
v6
Comments
sameertm 29-Nov-10 10:53am    
its showing error like this "A generic error occurred in GDI+. "
JF2015 29-Nov-10 11:00am    
Edited since I didn't notice that your code has 2 errors.
sameertm 29-Nov-10 11:07am    
no sir its showing same error
JF2015 29-Nov-10 11:10am    
Which line gives you this error?
sameertm 29-Nov-10 11:12am    
b.Save(path, Imaging.ImageFormat.Jpeg) this is line showing error ""A generic error occurred in GDI+"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900