이미 언급했듯이 기존 양식 위에 다른 컨트롤/양식을 겹쳐서 그 위에 회색 음영 버전을 렌더링하는 것이므로 추가 양식을 정확하게 배치하여이 작업을 수행 할 수 있습니다 원래 양식을 사용하거나 Panel
과 같은 것을 사용하여 다른 모든 컨트롤 위에 배치 할 수 있습니다.
다음은 첫 번째 양식의 클라이언트 영역 위에 다른 양식을 정확하게 배치 할 때 수행 할 수있는 작업 예제입니다. 된다는 사실을
using (Grayscale(this))
{
MessageBox.Show("Test");
}
구현
public static Form Grayscale(Form tocover)
{
var frm = new Form
{
FormBorderStyle = FormBorderStyle.None,
ControlBox = false,
ShowInTaskbar = false,
StartPosition = FormStartPosition.Manual,
AutoScaleMode = AutoScaleMode.None,
Location = tocover.PointToScreen(tocover.ClientRectangle.Location),
Size = tocover.ClientSize
};
frm.Paint += (sender, args) =>
{
var bmp = GetFormImageWithoutBorders(tocover);
bmp = ConvertToGrayscale(bmp);
args.Graphics.DrawImage(bmp, args.ClipRectangle.Location);
};
frm.Show(tocover);
return frm;
}
private static Bitmap ConvertToGrayscale(Bitmap source)
{
var bm = new Bitmap(source.Width, source.Height);
for (int y = 0; y < bm.Height; y++)
{
for (int x = 0; x < bm.Width; x++)
{
Color c = source.GetPixel(x, y);
var luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
bm.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
}
}
return bm;
}
private static Bitmap GetControlImage(Control ctl)
{
var bm = new Bitmap(ctl.Width, ctl.Height);
ctl.DrawToBitmap(bm, new Rectangle(0, 0, ctl.Width, ctl.Height));
return bm;
}
private static Bitmap GetFormImageWithoutBorders(Form frm)
{
// Get the form's whole image.
using (Bitmap wholeForm = GetControlImage(frm))
{
// See how far the form's upper left corner is
// from the upper left corner of its client area.
Point origin = frm.PointToScreen(new Point(0, 0));
int dx = origin.X - frm.Left;
int dy = origin.Y - frm.Top;
// Copy the client area into a new Bitmap.
int wid = frm.ClientSize.Width;
int hgt = frm.ClientSize.Height;
var bm = new Bitmap(wid, hgt);
using (Graphics gr = Graphics.FromImage(bm))
{
gr.DrawImage(wholeForm, 0, 0,
new Rectangle(dx, dy, wid, hgt),
GraphicsUnit.Pixel);
}
return bm;
}
}
참고 사용 방법 :
- 이
Paint
의 구현은 매우 가난을 - 그레이 스케일 이미지가 사전되도록 정말 이중 버퍼링을 사용해야합니다 버퍼링 된 그래픽 컨텍스트에 렌더링되므로, Paint 메서드는 미리 그려진 버퍼 내용을 그릴 필요가 있습니다. Custom Drawing Controls in C# – Manual Double Buffering
ConvertToGrayscale
가 느린 측에 조금이지만, 아마도 누군가가
- 이미지가 정적 어떤 이유로 원래의 형태를 이동 관리하는 경우, 잘못 기본 제어하면됩니다
- 상황을 가속화 할 수 있습니다 참조 다시 그리면 맨 위 양식도 다시 그려야합니다. 다른 양식의 일부가 무효화되었을 때이를 어떻게 감지하는지 잘 모르겠습니다.
시간을 찾으면 그 중 일부 문제를 해결할 것입니다.하지만 위의 사항은 일반적인 아이디어를 제공합니다.
WPF에서는이 작업이 훨씬 쉽습니다.
출처 :
나는 회색 형태가 폼에 추가 컨트롤을 추가하는 것입니다 수 있도록하는 데 사용하는 신속하고 더러운 트릭. 그 컨트롤은 그것의 부모 ('Form.DrawToBitmap()')의 사진을 찍을 것이고, 그것을 조작하고, 그것을 배경으로 사용하고, 완전한 형태를 채우기 위해 최대화 할 것입니다. – Bobby
회색 음영이 아닌 회색 음영 – Indy9000
@Indeera 어느 쪽이든 맞습니다. http://en.wikipedia.org/wiki/Grayscale – Keplah