bitmapsource

Is BitmapSource the only type can be used in Image Source?

We can use Bitmapsource object as the content of a Image control, However if I only have Bitmap object, can I use it directly, if I convert Bitmap to Bitmapsouce using the following method: Bitmap bitmap = imageObjToBeConvert; IntPtr HBitmap = bitmap.GetHbitmap(); result = Imaging.CreateBitmapSourceFromHBitmap ...

using BitmapSource as Image source in WPF

Hello Everyone, I am trying to update an Image (_browserScreenshot below) object in XAML by changing the source image every time an event determines the source needs updating. Right now I have this: public BitmapSource GetScreen() { Bitmap bitmap = new Bitmap(app.Browser.ClientRectangle.Width, app.Browser.ClientRec...

Unable to retrieve TIFF pages from TiffBitmapDecoder.Frames -- all frames are page 1

I'm trying to convert a multipage tiff image into a multipage XPS document. The problem I'm having is with the TiffBitmapDecoder and its BitmapFrames. Here's the code: private static void ToXpsDocument(string imageName, string xpsName) { using (var p = Package.Open(xpsName)) { PackageStore.AddPackage(new Uri("pack://th...

How do you make sure WPF releases large BitmapSource from Memory?

System: Windows XP SP3, .NET 3.5, 4GB RAM, Dual 1.6gHz I have a WPF application that loads and transitions (using Storyboard animations) extremely large PNGs. These PNGs are 8190x1080 in resolution. As the application runs it appears to cache the images and the system Memory slowly creeps up. Eventually it chokes the system and throws ...

Image loading memory leak with C#

Hi, I have a memory leak issue in my application which loads a large amount of images. I'm rather new to C#, and thought my days of memory leak issues were past. I can't figure out the problem - maybe I'm using some unmanaged modules which I'm not handle correctly? To illustrate my problem I've simplified the core of what causes the p...

WPF Image won't display BitmapSource

I'm new to using WPF and GDI, and I'm having trouble displaying an image. My eventual goal is to build something expose-like. So far, I gray-out the screens, gather all the active HWNDs, and capture the screens of all the windows. For now, I have a single Image element that I try to set the source for, but nothing ever shows up. foreach...

Remove alpha from a BitmapSource

Hello, I use BitBlt() and CreateBitmapSourceFromHBitmap() to capture a window as a BitmapSource that I can display on an Image element in a WPF application. But for some reason, most of the application that it captures is transparent. Here is a source vs. capture image of what's happening: It's gray because the background of the wind...

Why does BitmapSource.Create throw an ArgumentException?

I'm trying to get an bitmap created from raw data to show in WPF, by using an Image and a BitmapSource: Int32[] data = new Int32[RenderHeight * RenderWidth]; for (Int32 i = 0; i < RenderHeight; i++) { for (Int32 j = 0; j < RenderWidth; j++) { Int32 index = j + (i * RenderHeight); if (i + j % 2 == 0) ...

WPF/BackgroundWorker and BitmapSource problem.

Hi, I am a beginner with WPF and trying a home project to become familiar with the technology. I have a simple form where the user selects an image file, I then display EXIF data along with a thumbnail of the image. This is working fine but when I select a RAW image file (~9 MB) there can be a slight delay while the thumb loads, so I ...

Is there a good way to convert between BitmapSource and Bitmap?

As far as I can tell the only way to convert from BitmapSource to Bitmap is through unsafe code... Like this (from Lesters WPF blog): myBitmapSource.CopyPixels(bits, stride, 0); unsafe { fixed (byte* pBits = bits) { IntPtr ptr = new IntPtr(pBits); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( width,...

InteropBitmap to BitmapImage

Hi, I'm trying to Convert a Bitmap (SystemIcons.Question) to a BitmapImage so I can use it in a WPF Image control. I have the following method to convert it to a BitmapSource, but it returns an InteropBitmapImage, now the problem is how to convert it to a BitmapImage. A direct cast does not seem to work. Does anybody know how to do i...

Convert WPF BitmapSource to Icon for window

I have a 16x16 .png file which I have loaded as an ImageSource (BitmapSource) and it is working fine when I use it on an Image in a tabcontrol header. I now want to use that same image in a floating window (inherited from the WPF Window class) when the user drags the document tab. (This is AvalonDock which I have tweaked to allow images...

How to copy DispatcherObject (BitmapSource) into different thread?

Hi, I am trying to figure out how can I copy DispatcherObject (in my case BitmapSource) into another thread. Use case: I have a WPF app that needs to show window in a new thread (the app is actually Outlook addin and we need to do this because Outlook has some hooks in the main UI thread and is stealing certain hotkeys that we need to u...

how to save a WPF image to a file

in WPF, the System.Windows.Clipboard.getImage() function returns a BitmapSource object. As a newbie in WPF coming from a WinForms background, its not clear to me how to save this image to a file. What are the steps I must take? ...

Display Image from Byte Array in WPF - Memory Issues

Hi, I've developed an application to capture and save images to a database, but I'm having an issue with memory usage. On my domain object I have 3 properties: Image - Byte array, contents are a jpg RealImageThumb - The byte array converted to a BitmapImage and shrunk, displayed to the user in a gridview with other thumbnails Real...

How to draw a line on an existing BitmapSource in WPF ?

Hello folks, I would like to draw a line (or any geometric shape) on an existing BitmapSource object in my WPF application. What is the best way to do it ? The BitmapSource is the result of a BitmapSource.Create(...) call. Thanks Romain ...

create an empty BitmapSource in C#

Waht is the fatest (few lines of code and low resource usage) way to create an empty (0x0px or 1x1px and fully transparent) BitmapSource instance in c# that wehn used renders nothing. ...

Is it possible to modify a WPF BitmapSource in memory 'unsafe'ly from another thread

I would like to do some processing of images in a WPF application. However, I would like to modify the pixels of a BitmapSource in memory at runtime. I'm currently managing to do this using 'unsafe' code against an old fashioned System.Drawing.Bitmap and it works a treat (lock a working area, fiddle with the pixels) job done. The approa...