C# 이미지 리소스

jiyul·2023년 12월 11일
0

C#

목록 보기
14/21
  1. 프로젝트 우클릭 > Add > New Item > Resource File
  2. Resource1.resx 파일에서 Add Resource > 이미지 파일 선택
  3. 솔루션 탐색기에 Resource 폴더 내부의 이미지 파일 선택 후 Properties 창에서 Build Action을 Resource로 변경

Build Action이란?

  • None : 실행 파일 또는 DLL에 포함되지 않음
  • Embedded Resource : DLL에 포함됨, GetManifestResourceStream으로 불러옴
  • Resource : DLL에 포함됨, URI를 통해 불러옴

예시

//상대경로
var uriSource = new Uri(@"/WpfApp1;component/Resources/dog.jpg", UriKind.Relative); //WpfApp1은 프로젝트명
ImageBox1.Source = new BitmapImage(uriSource);

//절대경로
Uri uriCatImage = new Uri(@"pack://application:,,,/Resources/cat.jpg", UriKind.Absolute);
Button1.Background = new ImageBrush(new BitmapImage(uriCatImage));
profile
Let's take the lead

0개의 댓글

관련 채용 정보