bitmapimage

BitmapImage: Accessing closed StreamSource

筅森魡賤 提交于 2019-12-02 06:54:04
问题 I'm using the following code trying to convert my BitmapImage to a byte[] so I can save it in my MS SQL Database. public static byte[] BufferFromImage(BitmapImage img) { if (img == null) return null; byte[] result = null; using (Stream stream = img.StreamSource) { if (stream != null && stream.Length > 0) { using (BinaryReader br = new BinaryReader(stream)) { result = br.ReadBytes((int)(stream.Length)); } } } return result; } Sadly this doesn't work as img.StreamSource is disposed when I try

BitmapImage from file PixelFormat is always bgr32

三世轮回 提交于 2019-12-02 05:15:00
问题 I am loading an image from file with this code: BitmapImage BitmapImg = null; BitmapImg = new BitmapImage(); BitmapImg.BeginInit(); BitmapImg.UriSource = new Uri(imagePath); BitmapImg.CacheOption = BitmapCacheOption.OnLoad; BitmapImg.CreateOptions = BitmapCreateOptions.IgnoreImageCache; BitmapImg.EndInit(); It works as expected except for the fact that no matter what kind of image I'm loading (24bit RGB, 8bit grey, 12bit grey,...), after .EndInit() the BitmapImage always has as Format bgr32.

Convert a dynamic BitmapImage to a grayscale BitmapImage in a Windows Phone application

回眸只為那壹抹淺笑 提交于 2019-12-02 05:04:02
I would like to Convert a BitmapImage to a Grayscale BitmapImage: Which I get from a method and therefore - the Width and Height are unknown to me. I have tried looking into options such as WritableBitmapEx and static extension methods but they haven't been helpful to me as I would like the return data type to be a BitmapImage as well as I then need to add it to List. Is this possible in a Windows Phone app using C#? I would really appreciate if someone would shed some light into this. Thank you. The Algorithm is pretty simple: using System.Windows.Media.Imaging; using System.IO; private

byte[] to BitmapImage conversion fails

为君一笑 提交于 2019-12-02 05:00:16
问题 I have a problem. I want to convert BitmapImage into byte[] array and back. I wrote these methods: public static byte[] ToByteArray(this BitmapImage bitmapImage) { byte[] bytes; using (MemoryStream ms = new MemoryStream()) { bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource.CopyTo(ms); bitmapImage.EndInit(); bytes = ms.ToArray(); } return bytes; } public static BitmapImage ToBitmapImage(this byte[] bytes, int width, int height) { BitmapImage

Loading image from cache using BitmapFactory.decodeStream() in Android

自闭症网瘾萝莉.ら 提交于 2019-12-02 04:44:36
UPDATES : Even if i don't retrieve images from cache, i tried to retrieve via Drawable where i stored all the 18 images in the "drawable-mdpi" folder. Still, a blank screen was display. I was able to retrieved images from the server and save the image (.GIF) into the cache. However, when i need to load that image from cache, the image doesn't show up on screen. Here is the codes that does the work: File cacheDir = context.getCacheDir(); File cacheMap = new File(cacheDir, smallMapImageNames.get(i).toString()); if(cacheMap.exists()){ FileInputStream fis = null; try { fis = new FileInputStream

WPF - using CroppedBitmap in DataTemplate

筅森魡賤 提交于 2019-12-02 03:30:54
问题 The following xaml works ok inside a Window : <Border Width="45" Height="55" CornerRadius="10" > <Border.Background> <ImageBrush> <ImageBrush.ImageSource> <CroppedBitmap Source="profile.jpg" SourceRect="0 0 45 55"/> </ImageBrush.ImageSource> </ImageBrush> </Border.Background> </Border> But when I use the equivalent code in a DataTemplate I get the following error in run-time: Failed object initialization (ISupportInitialize.EndInit). 'Source' property is not set. Error at object 'System

How to convert Colors to Grayscale in java with just the java.io.*; library?

穿精又带淫゛_ 提交于 2019-12-02 03:08:23
Well, i got this.. cause in my place they request it like that.. Well i have this: //some variables and coments are a possible code.. But i mean i don't know how to do it exactly, i found on internet that to convert R is the byte is in *0.21 with G is *0.71 i guess and blue is * 0.07. I just can use that library java.io.*; and i'm working with BMP format images of 1024 x 768, if you can help me, or you want me to be more specific please tell me. i don't know if i have to add another variables or to take some out, or to modify, please help me. I'm not so new in this language, but i'm not an

BitmapImage from file PixelFormat is always bgr32

妖精的绣舞 提交于 2019-12-02 02:27:41
I am loading an image from file with this code: BitmapImage BitmapImg = null; BitmapImg = new BitmapImage(); BitmapImg.BeginInit(); BitmapImg.UriSource = new Uri(imagePath); BitmapImg.CacheOption = BitmapCacheOption.OnLoad; BitmapImg.CreateOptions = BitmapCreateOptions.IgnoreImageCache; BitmapImg.EndInit(); It works as expected except for the fact that no matter what kind of image I'm loading (24bit RGB, 8bit grey, 12bit grey,...), after .EndInit() the BitmapImage always has as Format bgr32. I know there have been discussions on the net, but I have not found any solution for this problem. Does

WPF - using CroppedBitmap in DataTemplate

二次信任 提交于 2019-12-02 01:40:22
The following xaml works ok inside a Window : <Border Width="45" Height="55" CornerRadius="10" > <Border.Background> <ImageBrush> <ImageBrush.ImageSource> <CroppedBitmap Source="profile.jpg" SourceRect="0 0 45 55"/> </ImageBrush.ImageSource> </ImageBrush> </Border.Background> </Border> But when I use the equivalent code in a DataTemplate I get the following error in run-time: Failed object initialization (ISupportInitialize.EndInit). 'Source' property is not set. Error at object 'System.Windows.Media.Imaging.CroppedBitmap' in markup file. Inner Exception: {"'Source' property is not set."} The

Convert Base64 string to BitmapImage C# Windows Phone

拥有回忆 提交于 2019-12-01 23:37:18
问题 I receive a image/jpeg;base64 string from server. How can I convert this string to BitmapImage and set like Image.Source ? string imgStr = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD .... "; BitmapImage bmp = Base64StringToBitmap(imgStr); myImage.Source = bmp; Thanks in advance! 回答1: I find solution for my issue: public static BitmapImage Base64StringToBitmap(string base64String) { byte[] byteBuffer = Convert.FromBase64String(base64String); MemoryStream memoryStream = new MemoryStream