imagesource

Converting System.Drawing.Image to System.Windows.Media.ImageSource with no result

可紊 提交于 2019-12-10 14:01:54
问题 I would like to convert Image to ImageSource in my WPF app. I use Code128 library which works properly (already checked in WinForms app). Function below returns ImageSource with properly size, but nothing is visible. private ImageSource generateBarcode(string number) { var image = Code128Rendering.MakeBarcodeImage(number, 1, false); using (var ms = new MemoryStream()) { var bitmapImage = new BitmapImage(); image.Save(ms, ImageFormat.Bmp); bitmapImage.BeginInit(); ms.Seek(0, SeekOrigin.Begin);

Displaying a GIF in Silverlight

家住魔仙堡 提交于 2019-12-10 13:26:43
问题 I have a number of gifs in a folder on my web server /dir/subdir/bla.gif etc. On that same server is a Silverlight 3 application /ClientBin/bla.xap . Is there any way to display the gifs in the Silverlight app? I've tried <Image x:Name=img" /> and then in code setting this.img.Source=new BitmapImage(new Uri("/dir/subdir/bla.gif")) with no success. Any ideas welcome. 回答1: You might look into Silverlight ImageTools on Codeplex: http://imagetools.codeplex.com/ Project Description ImageTools for

still memory-leaks in .net4 - binding memory BitmapImage to Image-Source

做~自己de王妃 提交于 2019-12-10 09:44:56
问题 I know very similar questions were asked here in the past - but neither had a solution for my problem: I load a image from memory into a BitmapImage: private static BitmapImage LoadImage(byte[] imageData) { if (imageData == null || imageData.Length == 0) return null; var image = new BitmapImage(); using (var mem = new MemoryStream(imageData)) { mem.Position = 0; image.BeginInit(); image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; image.CacheOption = BitmapCacheOption.OnLoad;

How to convert Cursor to ImageSource

徘徊边缘 提交于 2019-12-08 10:24:57
问题 I have a .cur file path ( "%SystemRoot%\cursors\aero_arrow.cur" ) witch I want to display in an image control. So I need to convert Cursor to ImageSource. I tried both CursorConverter and ImageSourceConverter but had no luck. I also tried creating Graphics from the cursor and then converting it to Bitmap, But that didn't work either. Then I found the accepted answer in this thread: http://social.msdn.microsoft.com/Forums/vstudio/en-US/87ee395c-9134-4196-bcd8-3d8e8791ff27/is-there-any-way

Create thumbnail image directly from header-less image byte array

青春壹個敷衍的年華 提交于 2019-12-08 02:03:47
问题 My application shows a large number of image thumbnails at once. Currently, I am keeping all full size images in memory, and simply scaling the image in the UI to create the thumbnail. However, I'd rather just keep small thumbnails in memory, and only load the fullsize images when necessary. I thought this would be easy enough, but the thumbnails I'm generating are terribly blurry compared to just scaling the fullsize image in the UI. The images are byte arrays with no header information. I

Special behavior of MultiBinding vs Binding when specifying an ImageSource

▼魔方 西西 提交于 2019-12-07 17:07:35
问题 I ran into a special behavior when binding to the Source property of an Image , using a converter. It appears that if I use a simple Binding with a IValueConverter that returns a string correpsonding to a relative path to the image, everything is OK and the image is displayed. On the other hand, if I use a MultiBinding with a IMultiValueConverter that returns the same string, the binding doesn't work and this error message is displayed in VS2010 output window : System.Windows.Data Error: 5 :

How to compress image byte[] array to JPEG/PNG and return ImageSource object

喜你入骨 提交于 2019-12-06 06:27:27
问题 I have an image (in the form of a byte[] array) and I want to get a compressed version of it. Either a PNG or JPEG compressed version. I use the following code at the minute: private Media.ImageSource GetImage(byte[] imageData, System.Windows.Media.PixelFormat format, int width = 640, int height = 480) { return System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, format, null, imageData, width * format.BitsPerPixel / 8); } How do I extend this so that I can compress and

still memory-leaks in .net4 - binding memory BitmapImage to Image-Source

China☆狼群 提交于 2019-12-06 02:32:11
I know very similar questions were asked here in the past - but neither had a solution for my problem: I load a image from memory into a BitmapImage: private static BitmapImage LoadImage(byte[] imageData) { if (imageData == null || imageData.Length == 0) return null; var image = new BitmapImage(); using (var mem = new MemoryStream(imageData)) { mem.Position = 0; image.BeginInit(); image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; image.CacheOption = BitmapCacheOption.OnLoad; image.UriSource = null; image.StreamSource = mem; image.EndInit(); } image.Freeze(); return image; } And

Dispose StreamResourceInfo.Stream

笑着哭i 提交于 2019-12-05 07:29:27
I use StreamResourceInfo.Stream to get BitmapImage s from resources. Is it correct to Close and Dispose the stream after using it? I ask because in memory profiler, I get an error if I do so. Memory profiler says that a disposed instance has not been GCed. If I look on the web, I only can find this post to this topic. In this post, the responding person says, that it is meaninfull to dispose. However if I look at the circumstances and on the effect, I don't think that this is right. Does someone know what is the right action? Additional information: In the msdn examples I have seen, they don't

Get Imagesource from Memorystream in c# wpf

让人想犯罪 __ 提交于 2019-12-04 15:56:16
问题 How can I get ImageSource from MemoryStream in WPF using c# ? or convert MemoryStream to ImageSource to display it as image in wpf ? 回答1: using (MemoryStream memoryStream = ...) { var imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = memoryStream; imageSource.EndInit(); // Assign the Source property of your image image.Source = imageSource; } 来源: https://stackoverflow.com/questions/6588974/get-imagesource-from-memorystream-in-c-sharp-wpf