Bitmap newBitmap=null;
//a using (newBitmap=new Bitmap (panel1. Width, panel1. Height))
Using (newBitmap=new Bitmap (panel1. Width/2, panel1. Height))
{
//a complete screenshot
//panel1. DrawToBitmap (newBmp, new Rectangle (0, 0, newBmp Width, newBmp, Height));
//want to right half screenshots, but cut was left half, is shown in the right half of the purpose of rectangular
Panel1. DrawToBitmap (newBitmap, new Rectangle (newBitmap. Width/2, 0, newBitmap. Width/2, newBitmap, Height));
//show the screenshot
Image img=Image. FromHbitmap (newBitmap GetHbitmap ());
PictureBox1. Image=img;
}
Panel1. DrawToBitmap (newBitmap, new Rectangle (newBitmap. Width/2, 0, newBitmap. Width/2, newBitmap, Height));
This code is the hope of panel1 right half screenshots, but (newBitmap. Width/2, 0) this coordinate not capture target control starting intercept coordinates, but show starting in rectangular coordinates, intercept or from the source control of the upper left corner (0, 0) to capture, don't know is there any way to change this line of code from the source control in the middle of the start capture,
//screen coordinates positioning method can cut to the right half, but must be in the interface displayed after loading, and then execute the following code can be cut to winform form interface, or cutting is a computer desk surface corresponding to the area, do not conform to the requirements,
Bitmap newBitmap=new Bitmap (panel1. Width/2, panel1. Height);
Graphics g=Graphics. FromImage (newBitmap);
Point the SRC=https://bbs.csdn.net/topics/PointToScreen (new Point (panel1. Location. X + panel1. Width/2, panel1. Location. Y));
Point dest=new Point (0, 0);
Right opyFromScreen (SRC, dest, new Size (newBitmap. Width, newBitmap. Height), CopyPixelOperation. SourceCopy);
G.D ispose ();
//show the screenshot
Image img=Image. FromHbitmap (newBitmap GetHbitmap ());
PictureBox1. Image=img;
NewBitmap. The Dispose ();
To intercept target control right half way with DrawToBitmap methods are best done, baidu for a few days no problem, thank you!
CodePudding user response:
Public void DrawToBitmap (System. Drawing. The Bitmap Bitmap, System. Drawing. The Rectangle target Bounds);The targetBounds Chinese here is target box, refers to the rendering which position to the destination bitmap,
I think you are source Bounds, but DrawToBitmap does not support, perhaps you can the whole rendering, then half-and-half cut,
However, are more prone to make effect with other tools such as WPF,
In under the WPF, for example, we can put a WPF depending on the background of the yuan as a control to use:
& lt; Windows x:
XMLNS="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
XMLNS: x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800" & gt;
Height="{Binding ActualHeight, ElementName=myedit}" & gt;
CodePudding user response:
Thank you for your reply,DrawToBitmap problem you said is right, but the overall rendering and half-and-half cut method in my this not line,
Is because in the program according to the demand generated by container to a panel size is too big, use DrawToBitmap overall screenshots times wrong "parameter is invalid," and I'll think about cut twice, separately and together,
WPF doesn't work in this project, other tools I'll look for it,
CodePudding user response:
All the screenshots first, and then to capture the picture on the right half screenshots again;CodePudding user response: