Hello,
this is beli... im new to vb field.. trying to build a screen capture.. here is ma problem.. please help....
it should capture the part of the screen i want...
i hav made the picturebox transparent so that the back screen is visible..
the problem is , in every program and tutorials they talk abt capturing whole screen....
they use the code... screen.primaryscreen.bounds
here is ma coding.... the one related to capturing...
[code]Public Class main
Private Sub cmdcap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcap.Click
Me.Hide()
capturesceen()
Me.Show()
End Sub
Private Sub capturesceen()
Dim bounds As Rectangle
Dim xny As Point
Dim screenshot As System.Drawing.Bitmap
Dim graph As Graphics
bounds = pcbox.ClientRectangle
screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
pcbox.Image = screenshot
End Sub
Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim savefiledialog1 As New SaveFileDialog
Try
savefiledialog1.Title = "Save File"
savefiledialog1.FileName = "*.bmp"
savefiledialog1.Filter = "Bitmap |*.bmp"
If savefiledialog1.ShowDialog() = DialogResult.OK Then
pcbox.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
Catch ex As Exception 'Do Nothing
End Try
End Sub[/code]
when i googled about the same , i came across a similar case.. its weysform....a codeplex open source application...
the prob is, its written in C++ (i think so!) .. so help me..
here is the code , which i got frm codeplex website...
[code] private Image CaptureFullScreen()
{
Image MyImage;
this.Visible = false;
IntPtr dc1 = WinAPI.CreateDC("DISPLAY", null, null, (IntPtr)null);
Graphics g1 = Graphics.FromHdc(dc1);
MyImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
Visible = false;
dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
WinAPI.BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
Visible = true;
g2.Dispose();
return MyImage;
}
private Image CapturePartial()
{
Image MyImage;
this.Visible = false;
IntPtr dc1 = WinAPI.CreateDC("DISPLAY", null, null, (IntPtr)null);
Graphics g1 = Graphics.FromHdc(dc1);
MyImage = new Bitmap(captureArea.Width, captureArea.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
Visible = false;
dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
WinAPI.BitBlt(dc2, 0, 0, captureArea.Width, captureArea.Height, dc1, Left+captureArea.X, Top + captureArea.Y, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
Visible = true;
g2.Dispose();
return MyImage;
}
private void WeysForm_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
contextMenu.Show(this, new Point(e.X, e.Y));
}
private void WeysForm_DoubleClick(object sender, System.EventArgs e)
{
menuItemCaptureSave_Click(null, null);
}
[/code]
i hope thats enough to explain ma stuff... help me as soon as possible...
here is ma application looks.. ( just to show transparent thing...)
[IMG]http://i40.tinypic.com/2ip2qc.jpg[/IMG]
waitin for reply.. like anything.. its ma first project.. i dont want to leave it incomplete.. help....!!!!
i have also uploaded whole coding in text format....