본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - 이미지 파일 여러 형식으로 불러오기 ( string / 주소 / uri / jpg / jpeg / png / bmp / System.Drawing.Image / System.Windows.Media.Imaging.BitmapImage / System.Windows.Controls.Image )

728x90
반응형


 WPF & C# - 이미지 파일 여러 형식으로 불러오기 ( string / 주소 / uri / jpg / jpeg / png / bmp / System.Drawing.Image / System.Windows.Media.Imaging.BitmapImage / System.Windows.Controls.Image )



System.Drawing.Image



1
2
3
// System.Drawing.Image
string imgPath = "image.bmp";
System.Drawing.Image drawImg = System.Drawing.Image.FromFile(imgPath);
cs



System.Windows.Media.Imaging.BitmapImage



1
2
3
// System.Windows.Media.Imaging.BitmapImage
string imgPath = "image.bmp";
System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute));
cs




System.Windows.Controls.Image ( BitmapImage to System.Windows.Controls.Image )



1
2
3
4
5
// System.Windows.Controls.Image
string imgPath = "image.bmp";
System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute));
System.Windows.Controls.Image ctrlImg = new System.Windows.Controls.Image();
ctrlImg.Source = bi;
cs



위의 코드로 string Path 로 된 주소를 통해 이미지 파일을 불러 들일 수 있다.

728x90
반응형