Application/C# (WPF)

[C# WPF] Background 이미지 설정하기

devsalix 2023. 1. 17. 17:48
728x90

UIElement (Control)의 배경 이미지를 특정 파일로 설정하려면

 

string strImagePath = AppDomain.CurrentDomain.BaseDirectory + @"\img.jpg";
if (File.Exists(strImagePath))
{
	System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(strImagePath);
	BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap()
		, IntPtr.Zero
		, Int32Rect.Empty
		, BitmapSizeOptions.FromEmptyOptions());

	ImageBrush ib = new ImageBrush();
	ib.ImageSource = bitmapSource;
	TempControl.Background = ib;
}

 

위와 같이 코드를 작성하면 TempControl 의 배경 화면이

 

실행 파일의 같은 위치에 존재하는 img.jpg 파일로

 

배경화면이 지정됩니다

 


제 글이 도움이 되셨다면 댓글 & 공감 부탁드려요 😀

 

 
728x90