View previous topic :: View next topic |
Author |
Message |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Sat May 24, 2008 9:31 pm Post subject: ScreenShot help |
|
|
Edit: Code for "screenshot" button:
Code: | Me.WindowState = FormWindowState.Minimized
Dim bounds As Rectangle
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = Screen.PrimaryScreen.Bounds
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = screenshot |
Their something wrong here?????
NOTE: Coded in .NET
Basically I am workin on a screenshot program now.
I have created something that when you click "Take screenshot", it captures the screen, and pastes it into the window in a PictureBox.
There is another button called "Save" where it
1) Writes your image you captured into a .gif form in the folder "C:/temp/".
Problem: Writes the image and everything, but nothing is showing up. Basically you click it, windows picture viewer comes up, and "no image is available".
Here is the code for the save button:
Code: | Dim savef As New System.IO.StreamWriter("C:/temp/" + TextBox2.Text +".gif")
savef.Write(PictureBox1.Image)
savef.Close()
MsgBox("Picture Saved!")
|
2nd Problem: How do you make the form exit right before the screenshot, than re-appear?
_________________
Last edited by AndrewMan on Sun May 25, 2008 12:16 pm; edited 1 time in total |
|
Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat May 24, 2008 9:37 pm Post subject: |
|
|
Change form visibility. I don't know vb. But it's probably something like
Code: |
form1.visible = false
|
_________________
8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
Back to top |
|
 |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Sat May 24, 2008 9:41 pm Post subject: |
|
|
oib111 wrote: | Change form visibility. I don't know vb. But it's probably something like
Code: |
form1.visible = false
|
|
Tried that, than after screenshot I did
didn't work...
_________________
|
|
Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun May 25, 2008 5:35 am Post subject: |
|
|
To minimise:
Code: | Me.WindowState = FormWindowState.Minimized |
Declarations etcetera:
Code: |
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020
Private Background As Bitmap
Private fw, fh As Integer
Dim Counter As Integer
Protected Sub CaptureScreen()
Dim hsdc, hmdc As Integer
Dim hbmp, hbmpold As Integer
Dim r As Integer
hsdc = CreateDC("DISPLAY", "", "", "")
hmdc = CreateCompatibleDC(hsdc)
fw = GetDeviceCaps(hsdc, 8)
fh = GetDeviceCaps(hsdc, 10)
hbmp = CreateCompatibleBitmap(hsdc, fw, fh)
hbmpold = SelectObject(hmdc, hbmp)
r = BitBlt(hmdc, 0, 0, fw, fh, hsdc, 0, 0, 13369376)
hbmp = SelectObject(hmdc, hbmpold)
r = DeleteDC(hsdc)
r = DeleteDC(hmdc)
Background = Image.FromHbitmap(New IntPtr(hbmp))
DeleteObject(hbmp)
End Sub
|
Then to get a screenshot:
Code: | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CaptureScreen()
Counter = Counter + 1 'Used for screenshot saves (screenshot1, screenshot2 etc.)
PictureBox1.Image = Background 'Put the image in the picturebox
PictureBox1.Image.Save(txtScreenDir.Text & "\" & Counter & ".png", Imaging.ImageFormat.Png)
End Sub |
Make a counter variable so it saves the screenshots correctly (screen1, screen2 etc). You may also want to check if the clipboard contains an image (If Clipboard.ContainsImage Then) before you save it.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun May 25, 2008 5:50 am Post subject: |
|
|
@Typhoon808: Please credit your code properly if you are going to copy and paste from somewhere else.
_________________
- Retired. |
|
Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun May 25, 2008 7:49 am Post subject: |
|
|
My bad, I'm not sure where I got it from. I've had it in a text document for a while now.
|
|
Back to top |
|
 |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Sun May 25, 2008 9:42 am Post subject: |
|
|
Thanks guys. Ill try these codes out later to see if they work. But I know how to take a screenshot and paste it into a picturbox, just not sure how to save and make the form not visible.
_________________
|
|
Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun May 25, 2008 10:00 am Post subject: |
|
|
Best is to just make the form minimise. Use PictureBox1.Image.Save("directoryhere.png", Imaging.ImageFormat.Png) to save the image.
|
|
Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun May 25, 2008 11:14 am Post subject: |
|
|
or there is the bitblt method >.>
_________________
|
|
Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun May 25, 2008 11:47 am Post subject: |
|
|
I believe that there are managed ways of doing this, but I'm not sure.
You should Google around a bit for managed ways of taking screen shots.
Edit:
You could always send the Print Screen key (VK_SNAPSHOT = 0x2C), then use Clipboard.GetImage() or something in that class. =P
_________________
Last edited by samuri25404 on Sun May 25, 2008 12:52 pm; edited 1 time in total |
|
Back to top |
|
 |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Sun May 25, 2008 12:02 pm Post subject: |
|
|
blankrider wrote: | or there is the bitblt method >.> |
That gets way to confusing. Im trying to make it as simple as a I can.
I got the save thing to work... but I cant get the minimize thing to work.
_________________
|
|
Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun May 25, 2008 12:12 pm Post subject: |
|
|
AndrewMan wrote: | blankrider wrote: | or there is the bitblt method >.> |
That gets way to confusing. Im trying to make it as simple as a I can.
I got the save thing to work... but I cant get the minimize thing to work. |
I prefer to use faster more improved ways of doing things. If not, i would just MFC everything and use fancy wrappers.
But that's just me.
_________________
|
|
Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sun May 25, 2008 3:17 pm Post subject: |
|
|
I re-did it in c# with the fix.
Code: |
Rectangle bounds = Screen.PrimaryScreen.Bounds;
Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics graph = Graphics.FromImage(screenshot);
this.Visible = false;
System.Threading.Thread.Sleep(1000);
graph.CopyFromScreen(0, 0, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); // The first two should always be 0 if it's the desktop
picCap.Image = screenshot;
this.Visible = true;
|
To save, you can do it with one line of code.
Code: |
PictureBox1.Image.Save(<Location>);
|
|
|
Back to top |
|
 |
|