Questions tagged [bitmapsource]

Bitmapsource represents a single, constant set of pixels at a certain size and resolution.

What questions should have this tag:
.Net Framework questions utilizing the BitmapSource class under the System.Windows.Media.Imaging namespace.

Basic Definitions:
Maximum height and width of an image: 2^16 pixels at 32 bits per channel * 4 channels
Maximum size of a BitmapSource: 2^32 bytes (64 gigabytes)
Maximum image size: 4 (four) gigapixels
Minimum image size: 1x1

Brief Introduction:
Part of the Windows Presentation Foundation (WPF) imaging pipeline, BitmapSource represents a single, constant set of pixels at a certain size and resolution. Multi-frame images and animations are not represented by BitmapSource.

Important Links:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx

136 questions
50
votes
6 answers

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…
JohannesH
  • 6,430
  • 5
  • 37
  • 71
43
votes
2 answers

How to save a WPF BitmapSource 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?
tbischel
  • 6,337
  • 11
  • 51
  • 73
28
votes
2 answers

fast converting Bitmap to BitmapSource wpf

I need to draw an image on the Image component at 30Hz. I use this code : public MainWindow() { InitializeComponent(); Messenger.Default.Register(this, (bmp) => { …
Titouan56
  • 6,932
  • 11
  • 37
  • 61
21
votes
2 answers

BitmapSource to BitmapImage

I need to parse the content of Clipboard.GetImage() (a BitmapSource) to a BitmapImage. Does anyone knows how can this be done?
Jaime Oro
  • 9,899
  • 8
  • 31
  • 39
16
votes
1 answer

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…
discorax
  • 1,487
  • 4
  • 24
  • 39
12
votes
3 answers

In WPF, can I share the same image resource between 2 buttons

I want to create a On/Off button in WPF and I want it to change its appearance when the user clicks it (if it was on switch to off, if it wad off switch to on) using images. I added the images I want to use to the resources:
Tamar Cohen
  • 1,272
  • 2
  • 16
  • 28
10
votes
3 answers

Image loading memory leak with C#

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…
stiank81
  • 25,418
  • 43
  • 131
  • 202
9
votes
1 answer

Copying from BitmapSource to WritableBitmap

I am trying to copy a part of a BitmapSource to a WritableBitmap. This is my code so far: var bmp = image.Source as BitmapSource; var row = new WriteableBitmap(bmp.PixelWidth, bottom - top, bmp.DpiX, bmp.DpiY, bmp.Format,…
Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
9
votes
6 answers

create an empty BitmapSource in C#

What is the fastest (few lines of code and low resource usage) way to create an empty (0x0 px or 1x1 px and fully transparent) BitmapSource instance in c# that is used when nothing should be rendered.
bitbonk
  • 48,890
  • 37
  • 186
  • 278
8
votes
1 answer

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++) …
Mike Pateras
  • 14,715
  • 30
  • 97
  • 137
8
votes
1 answer

What is the relevance of DPI in BitmapSource.Create() method?

i read the Wikipedia article on DPI, but it confused me even more... i don't have any DPI information on the image. What DPI should i use with BitmapSource.Create(), is it OK to use a constant one(96/72?) and does it really matter if i'm not going…
UIlrvnd
  • 786
  • 6
  • 20
7
votes
1 answer

How do I convert from a Brush (e.g. DrawingBrush) to a BitmapSource?

I have a DrawingBrush with some vector graphics. I want to convert it to BitmapSource as an intermediate step to getting it to Bitmap. What's the (best) way to do this?
Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
7
votes
1 answer

How can I get the PixelFormat of a BitmapSource

I am using the following to convert a BitmapSource to a Bitmap: internal static Bitmap ConvertBitmapSourceToBitmap(BitmapSource bitmapSrc) { int width = bitmapSrc.PixelWidth; int height = bitmapSrc.PixelHeight; int stride = width *…
Matt Bond
  • 1,402
  • 12
  • 19
6
votes
1 answer

C# WPF BitmapSource Memory Leak?

I'm developing a BlackJack program which shows a BlackJack Table, cards, etc. The plan is that it'll be playing thousands of hands one after another with an automated strategy. I have a PlayerSeat UserControl which contains an ItemsControl bound to…
Caesar Kabalan
  • 753
  • 1
  • 8
  • 18
6
votes
2 answers

BitmapSource from embedded image

My goal is to draw image "someImage.png", which is embedded resource, on WPF window, in overridden OnRender method: protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); …
StraGan
  • 73
  • 1
  • 3
1
2 3
9 10