私はいくつかのコントロールを持つc#windowsフォームを持っています。コントロールの一部は、コントロールの一部です。フォームからコントロールを入力するために必要な関数が必要で、コントロールの背後にあるイメージを返します。例:フォームに背景イメージがあり、その上にボタンが含まれている場合 - この関数を実行すると、ボタンの背後にある背景イメージの部分が得られます。任意のアイデアとコード?c#winforms:コントロールの背後にあるスクリーンショットイメージの取得
H-E-L-P !!!
私はいくつかのコントロールを持つc#windowsフォームを持っています。コントロールの一部は、コントロールの一部です。フォームからコントロールを入力するために必要な関数が必要で、コントロールの背後にあるイメージを返します。例:フォームに背景イメージがあり、その上にボタンが含まれている場合 - この関数を実行すると、ボタンの背後にある背景イメージの部分が得られます。任意のアイデアとコード?c#winforms:コントロールの背後にあるスクリーンショットイメージの取得
H-E-L-P !!!
これはかなり簡単です。フォーム上の各コントロールは、あなたがそうのように、新しいRectangleをインスタンス化するために使用できるサイズとLocationプロパティ、持っている:コントロールの後ろに配置、背景画像の一部を含むビットマップを取得するには
Rectangle rect = new Rectangle(button1.Location, button1.Size);
を、最初に、適切な寸法のビットマップを作成します。
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
あなたは、新しいビットマップのためのGraphicsオブジェクトを作成して、背景画像の一部をコピーして、そのオブジェクトのdrawImageメソッドを使用します。
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(...); // sorry, I don't recall which of the 30 overloads
// you need here, but it will be one that uses form1.Image as
// the source, and rect for the coordinates of the source
}
これは、そのコントロールの下にある背景イメージの部分を含む新しいビットマップ(bmp)を残します。
申し訳ありません申し訳ありませんが、私はコード内で具体的には言えません。私は公衆端末にいます。しかし、Intellisense情報はDrawImageメソッドのために渡す必要があることを教えてくれます。
これは私の最初の推測ですが、テストする必要があります。
RestablishボタンのclientRectangleにキャプチャ現在の画面
public static Image GetBackImage(Control c) {
c.Visible = false;
var bmp = GetScreen();
var img = CropImage(bmp, c.ClientRectangle);
c.Visible = true;
}
public static Bitmap GetScreen() {
int width = SystemInformation.PrimaryMonitorSize.Width;
int height = SystemInformation.PrimaryMonitorSize.Height;
Rectangle screenRegion = Screen.AllScreens[0].Bounds;
var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(screenRegion.Left, screenRegion.Top, 0, 0, screenRegion.Size);
return bitmap;
}
public static void CropImage(Image imagenOriginal, Rectangle areaCortar) {
Graphics g = null;
try {
//create the destination (cropped) bitmap
var bmpCropped = new Bitmap(areaCortar.Width, areaCortar.Height);
//create the graphics object to draw with
g = Graphics.FromImage(bmpCropped);
var rectDestination = new Rectangle(0, 0, bmpCropped.Width, bmpCropped.Height);
//draw the areaCortar of the original image to the rectDestination of bmpCropped
g.DrawImage(imagenOriginal, rectDestination, areaCortar, GraphicsUnit.Pixel);
//release system resources
} finally {
if (g != null) {
g.Dispose();
}
}
}
私は彼がコントロールの下にあり、フォームの背後にあるもののイメージを望んでいるとは思わない - 彼はちょうどコントロールの下のフォームに何を望んでいる。 – MusiGenesis
私はちょうどボタンを表示しているので、効果はそれの背後にある画像を取得しています –
あなたが何をしようとしてのいくつかの情報を投稿してもらえますか? –