bitmapimage

WPF BitmapImage Serialization/Deserialization

巧了我就是萌 提交于 2019-11-26 22:24:36
问题 I've been trying to Serialize and Deserialize BitmapImages. I've been using methods which supposedly works which I found in this thread: error in my byte[] to WPF BitmapImage conversion? Just to iterate what is going on, here is part of my Serialization code: using (MemoryStream ms = new MemoryStream()) { // This is a BitmapImage fetched from a dictionary. BitmapImage image = kvp.Value; PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(image)); encoder

How do I convert a WriteableBitmap object to a BitmapImage Object in WPF

微笑、不失礼 提交于 2019-11-26 22:03:03
问题 How do I convert a WriteableBitmap object to a BitmapImage Object in WPF? This link covers silverlight, the process is not the same in WPF as the WriteableBitmap object does not have a SaveJpeg method. So my question is How do I convert a WriteableBitmap object to a BitmapImage Object in WPF? 回答1: You can use one of the BitmapEncoders to save the WriteableBitmap frame to a new BitmapImage In this example we will use the PngBitmapEncoder but just choose the one that fits your situation. public

BitmapImage in WPF does lock file

蹲街弑〆低调 提交于 2019-11-26 21:02:40
I use: Dim bmi As New BitmapImage(New Uri(fiInfo.FullName, UriKind.Absolute)) bmi.CacheOption = BitmapCacheOption.OnLoad this does not Use OnLoad And file still is locked to overwrite on harddisk. Any idea how to unlock? Regards As shown in the question you link to, you'd need to call BeginInit and EndInit, like so as well as set the UriSource property: Dim bmi As New BitmapImage() bmi.BeginInit() bmi.CacheOption = BitmapCacheOption.OnLoad bmi.UriSource = New Uri(fiInfo.FullName, UriKind.Absolute) bmi.EndInit() Read the BitmapImage from file and rewrite it with a MemoryStream : MemoryStream ms

pass a bitmap image from one activity to another

。_饼干妹妹 提交于 2019-11-26 20:45:25
问题 In my app i am displaying no.of images from gallery from where as soon as I select one image , the image should be sent to the new activity where the selected image will be set as background.However, I am able to get the images from gallery but as soon as I select one the application crashes.Thanks in advance Activity-1(The images are shown in gallery and the selected image is sent to new activity) public class Gallery extends Activity { private static int RESULT_LOAD_IMAGE = 1; /** Called

convert array of bytes to bitmapimage

一个人想着一个人 提交于 2019-11-26 17:49:28
I'm going to convert array of bytes to System.Windows.Media.Imaging.BitmapImage and show the BitmapImage in an image control. When I'm using the first code, noting happens! no error and no image is displayed. But when I'm using the second one it works fine! can anyone say what is going on? first code is here: public BitmapImage ToImage(byte[] array) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(array)) { BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = ms; image.EndInit(); return image; } } second code is here: public BitmapImage ToImage(byte[]

byte[] to BitmapImage in silverlight

牧云@^-^@ 提交于 2019-11-26 17:16:55
问题 For the purpose of a game, I need to serialize some pictures in a binary file through a WPF application, using bitmapEncoder and its child classes. But these class are not available in silverlight, so I can't load them into the browser from the same binary file. Does someone know how to convert a byte[] to BitmapImage in silverlight? Thanks, KiTe 回答1: Try something like this: BitmapImage GetImage( byte[] rawImageBytes ) { BitmapImage imageSource = null; try { using ( MemoryStream stream = new

Memory consumption of BitmapImage/Image control in Windows Phone 8

╄→гoц情女王★ 提交于 2019-11-26 17:02:40
问题 I am testing a WP8 app and it's image viewer to show many images, I found app's memory consumption is raising and want to find out how to solve it. I've read some articles from web, however the solutions provided by those articles are not working on my app, please read the history below. First, I found the article "Image Tips for Windows Phone 7" and download its sample to do clean image cache testing, it's working with 1 image . And then for testing purposes, I make this app compiled with 15

Creating WPF BitmapImage from MemoryStream png, gif

删除回忆录丶 提交于 2019-11-26 16:25:47
I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if (stream.CanRead) { Byte[] buffer = new Byte[webResponse.ContentLength]; stream.Read(buffer, 0, buffer

Save BitmapImage to File

爱⌒轻易说出口 提交于 2019-11-26 15:27:43
I am working on a program that downloads images from a URL to a bitmapimageand displays it. Next I try to save the bitmapimage to the harddrive using jpegbitmapencoder. The file is successfully created but the actual jpeg image is empty or 1 black pixel. public Guid SavePhoto(string istrImagePath) { ImagePath = istrImagePath; BitmapImage objImage = new BitmapImage( new Uri(istrImagePath, UriKind.RelativeOrAbsolute)); PictureDisplayed.Source = objImage; savedCreationObject = objImage; Guid photoID = System.Guid.NewGuid(); string photolocation = photoID.ToString() + ".jpg"; //file name

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

喜你入骨 提交于 2019-11-26 13:56:02
问题 I am working with Images in Java, I have designed more over 100+ images(.png) format, They were all Trasparent and Black Color Drawing. The problem is, Now I have been asked to change the color of the Drawing (Black -to ). I have searched many code snipped at google,that changes the Bitmap (pixels) of the Image, but i am not guessing what i have to do to match the exact pixel and replace specially when the images if in Transparent mode. Below is the code in .Net (C#) Bitmap newBitmap = new