본문 바로가기

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

WPF & C# - 이미지 넣기 ( image / img / BitmapImage / Uri / pack / ico / riKind.Relative / Uniform / None / UniformToFill / Fill / 가로세로비율 )

728x90
반응형


 WPF & C# - 이미지 넣기 ( image / img / BitmapImage / Uri / pack / ico / riKind.Relative / Uniform / None / UniformToFill / Fill / 가로세로비율 )









1
2
3
4
Image image = new Image();
image.Source = new BitmapImage(new Uri("pack://siteoforigin:,,,/Resources/cloud.png"));
// new Uri("pack://application:,,,/;component/cloud.png", UriKind.Absolute);
 
cs



실행파일과 같은 폴더에 있을 때


1
2
3
Image image = new Image();
string fileName = "/01.png";
image.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + fileName, UriKind.RelativeOrAbsolute));
cs



1
2
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
img.Source = new BitmapImage(new Uri("image.png",UriKind.Relative));
cs



* 반드시 해당 파일의 '빌드작업'Resource 로 바꿔줘야 한다.

이거 몰라서 한참 헤맸다.


URIs for accessing the binary resources

URI

Resource

Logo.jpg
  • embedded in current assembly (using “Resource” as build action)
  • loose resource however physical file is placed along with xaml file or assembly (if selected build action is “Content”)
“A/B/Logo.jpgsame as above but resource file is located in subfolder “A/B”
“D:\Resource\Logo.jpgresource path hard coded
http://pinvoke.net/logo.jpgloose resource hosted at pinvoke.net website.
ResourceDll;component/Logo.jpgthis URI represents the resource embedded in assembly ResourceDLL.dll or ResourceDLL.exe
ResourceDll;componen/tA/B/Logo.jpgsame as above except resource is located in subfolder
pack://siteOfOrigin:,,,/logo.jpgresource located at site of origin
pack://siteOfOrigin:,,,/A/B/logo.jpg

resource located at site of origin in sub folder


[출처 및 참고]

http://six605.tistory.com/569


https://csharpsimplified.wordpress.com/2009/02/16/resources-in-wpf-i-binary-resources/


https://msdn.microsoft.com/ko-kr/library/aa970069(v=vs.110).aspx


https://msdn.microsoft.com/ko-kr/library/system.windows.window.icon(v=vs.110).aspx


https://msdn.microsoft.com/ko-kr/library/system.windows.controls.image.source(v=vs.110).aspx







이미지 사이즈

Uniform = 나오게

None = 원래 사이즈 대로 ( Default 값 )

UniformToFill = 가로 길이에 맞춤

Fill = 가로세로 꽉차게 함


참고 : http://insurang.tistory.com/247 ( 가로세로 비율 )


728x90
반응형