Home > Net >  Questions about winform controls screenshots. Help!!!!!!
Questions about winform controls screenshots. Help!!!!!!

Time:11-10

Requirements: winform, interface with a panel1 container, there are some controls that need to panel1 right half screenshots:

 
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:

reference 3/f E time Mr Reply:
all the screenshots first, then to capture images of the right half screenshots again;

Thank you for your reply,

Because the panel container size is too big, all the screenshots complains "parameter is invalid" and I'll think about separate cut twice, and then together,

Don't know is there any way for the panel in the screenshot geometric narrow screenshots, screenshots of the whole after such narrow size is ok,

CodePudding user response:

reference 4 floor ddsxd19 response:
Quote: reference 3/f E time Mr Reply:
all the screenshots first, then to capture images of the right half screenshots again;

Thank you for your reply,

Because the panel container size is too big, all the screenshots complains "parameter is invalid" and I'll think about separate cut twice, and then together,

Don't know is there any way for the panel in the screenshot geometric narrow screenshots, so that to reduce the size after overall screenshots,


Although no this is not a big figure;
But I think if I can intercept part of the screen display, image translation, the goal is to make the hidden part appears in the display screen;

CodePudding user response:

CopyFromScreen method screenshot above screen outside the scope of the section

CodePudding user response:

Have bosses can rewrite DrawToBitmap method with a parameter SourcePoint specify the source control, the starting point of the screenshot

CodePudding user response:

So that the panel you have how old?

CodePudding user response:

references 9 f Learn_change_myself response:
so that the panel you have how old?

Generated by the panel size in 9000 * 7000,
But there are size may not be a problem, because sometimes it is not an error, can run normally, error probability about half half,

Abnormal reason I feel is more likely to be too much memory, when I was debugging see screenshot program memory of more than 300000 K,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related