■ BitmapImage 클래스 : 웹에서 비트맵 이미지 구하기
------------------------------------------------------------------------------------------------------------------------
using System;
using System.IO;
using System.Net;
using System.Windows.Media.Imaging;
#region 비트맵 이미지 구하기 - GetBitmapImage(sourceURI)
/// <summary>
/// 비트맵 이미지 구하기
/// </summary>
/// <param name="sourceURI">소스 URI</param>
/// <returns>비트맵 이미지</returns>
public BitmapImage GetBitmapImage(string sourceURI)
{
byte[] bufferArray;
if(sourceURI.Substring(0, 4).ToLower().Equals("http"))
{
WebClient webClient = new WebClient();
bufferArray = webClient.DownloadData(new Uri(sourceURI, UriKind.Absolute));
webClient.Dispose();
}
else
{
bufferArray = File.ReadAllBytes(sourceURI);
}
MemoryStream memoryStream = new MemoryStream(bufferArray);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
return bitmapImage;
}
#endregion
------------------------------------------------------------------------------------------------------------------------
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기 (0) | 2019.05.30 |
---|---|
[C#/WPF] 메모리 손실이 없는 비트맵 소스 구하기 (0) | 2019.05.30 |
[C#/WPF] AppDomain 클래스 : 동일 프로세스에서 멀티 WPF 애플리케이션 실행하기 (0) | 2019.05.30 |
[C#/WPF] 다중 UI 스레드 윈도우 사용하기 (0) | 2019.05.30 |
[C#/WPF] ScrollViewer 클래스 : 마우스를 사용해 스크롤하기 (0) | 2019.05.28 |
[C#/WPF] BitmapImage 클래스 : 웹에서 비트맵 이미지 구하기 (0) | 2019.05.27 |
[C#/WPF] BitmapImage 클래스 : 비트맵 이미지 구하기 (0) | 2019.05.27 |
[C#/WPF] ScrollViewer 클래스 : IsDeferredScrollingEnabled 속성을 사용해 스크롤 성능 높이기 (0) | 2019.05.27 |
[C#/WPF] FrameworkElement 클래스 : RequestBringIntoView 이벤트를 사용해 ScrollViewer 내부 객체 포커스시 자동 스크롤 방지하기 (0) | 2019.05.27 |
[C#/WPF] 컨트롤 이미지 저장하기 (0) | 2019.05.27 |
[C#/WPF] VisualBrush 엘리먼트 : 격자 그리기 (0) | 2019.05.27 |
댓글을 달아 주세요