byte[] to BitmapImage in silverlight

Try something like this: BitmapImage GetImage( byte[] rawImageBytes ) { BitmapImage imageSource = null; try { using ( MemoryStream stream = new MemoryStream( rawImageBytes ) ) { stream.Seek( 0, SeekOrigin.Begin ); BitmapImage b = new BitmapImage(); b.SetSource( stream ); imageSource = b; } } catch ( System.Exception ex ) { } return imageSource; }

Memory consumption of BitmapImage/Image control in Windows Phone 8

I was dealing with the same problem and I think, in the end, that actually I’ve found a workaround, I am not a pro programmer but here is my solution: public Task ReleaseSingleImageMemoryTask(MyImage myImage, object control) { Pivot myPivot = control as Pivot; Task t = Task.Factory.StartNew(() => { Deployment.Current.Dispatcher.BeginInvoke(() => { if (myImage.img.UriSource != … Read more

Reloading an image in wpf

Found an answer that works for me: BitmapImage _image = new BitmapImage(); _image.BeginInit(); _image.CacheOption = BitmapCacheOption.None; _image.UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache); _image.CacheOption = BitmapCacheOption.OnLoad; _image.CreateOptions = BitmapCreateOptions.IgnoreImageCache; _image.UriSource = new Uri(@”Y:/screenshots/naratco08-0-0-screenshot.png”, UriKind.RelativeOrAbsolute); _image.EndInit(); ScreenAtco01Image.Source = _image;

How to Change Pixel Color of an Image in C#.NET

Here is the Solution I have done with Pixels. Attaching the source code so one can try the exact and get the result. I have sample images of 128×128 (Width x Height). using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.IO; //using System.Globalization; namespace colorchange { class Program { static void Main(string[] … Read more

How to free the memory after the BitmapImage is no longer needed?

I believe the solution you are looking for is at http://www.ridgesolutions.ie/index.php/2012/02/03/net-wpf-bitmapimage-file-locking/. In my case, I was trying to find a way to delete the file after it was created, but it appears to be a solution to both issues. Doesn’t free up memory: var bitmap = new BitmapImage(new Uri(imageFilePath)); Frees up memory, and allows file … Read more

BitmapImage to byte[]

To convert to a byte[] you can use a MemoryStream: byte[] data; JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapImage)); using(MemoryStream ms = new MemoryStream()) { encoder.Save(ms); data = ms.ToArray(); } Instead of the JpegBitmapEncoder you can use whatever BitmapEncoder you like as casperOne said. If you are using MS SQL you could also use a image-Column … Read more