도전2022

c#, wpf 에서 파일 주소를 브러쉬 데이터로 만들자. 본문

소스코드

c#, wpf 에서 파일 주소를 브러쉬 데이터로 만들자.

hotdigi 2012. 5. 3. 19:47

        private Brush resourceToBitmap(string p)

        {

            //Bitmap img = TJ01B.Properties.Resources.BkFullHd;

            var bitmap = new BitmapImage();

            if (!File.Exists(p)) return null;

            var source = File.OpenRead(p);

            bitmap.BeginInit();

            bitmap.CacheOption = BitmapCacheOption.OnLoad;

            bitmap.StreamSource = source;

            bitmap.EndInit();

            source.Close();

            source.Dispose();

            ImageBrush berriesBrush = new ImageBrush();

            berriesBrush.ImageSource = bitmap;

            return berriesBrush;

        }




호출 방법은 


img01.Background = resourceToBitmap(stringImgFile);

'소스코드' 카테고리의 다른 글

24 bit bmp to rGB565 file conversion[c#]  (0) 2012.05.08
PC에서 안드로이드 실행  (0) 2012.05.04
SHGetFolderPath  (0) 2012.04.25
ffmpeg  (0) 2012.04.25
The script on this page appears to have a problem. do you want to stop the script?  (0) 2012.04.13