Questions tagged [writeablebitmap]

Bitmaps are generally implemented as immutable objects in WPF. What this means is that once you create a bitmap you can't make any changes to it. You can manipulate bitmaps by creating new versions, which then immediately become immutable and sometimes this is a good way to work. Immutable bitmaps can be very efficient unless you want to indulge in a lot of dynamic changes in which case the overhead of creating and destroying them rapidly becomes too expensive. In this situation you need something a little more flexible - the WriteableBitmap. The WriteableBitmap, as its name suggests, isn't immutable and you can get at its individual pixels and manipulate them as much as you want. This is the ideal way to work when you need dynamic bitmaps. So let’s take a look at WriteableBitmap, how it works and how to use it to do dynamic things. Notice that the WriteableBitmap class in Silverlight is very different to the same class in WPF. To use WriteableBitmap we need to add:

using System.Windows.Media.Imaging;

which contains all of the additional bitmap facilities we need. You can create a WriteableBitmap in two ways. The most commonly used is to simply specify the size and format of the bitmap:

 WriteableBitmap wbmap = new 
      WriteableBitmap(100, 100, 300,
       300, PixelFormats.Bgra32, null);

This specifies a WriteableBitmap 100 by 100 pixels with a resolution of 300dpi by 300 dpi using a Bgra32 pixel format. Each pixel, a 32-bit int, uses a four-byte BGRA – that is the pixel is made up of a byte giving the Blue, Green, Red and Alpha values. The final parameter is used to specify a palette if the format needs one. You can specify a wide range of formats for the bitmap you create and in each case each pixel takes a given number of bits to represent and you need to find out how the bits allocated to each pixel determine its colour. The second method of creating a WriteableBitmap is to base it on an existing BitmapSource or derived class. For example, you should be able to create a WriteableBitmap from a standard bitmap using the constructor: WriteableBitmap(bitmapsource); but if you try this with a BitmapImage loaded from a URI you will get a null object error. The reason is that the bitmap might not yet be downloaded. For a local file the bitmap load blocks execution until it is loaded:

 Uri uri = new Uri(@"pack://application:
       ,,,/Resources/mypic.jpg");
 BitmapImage bmi = new BitmapImage(uri);
 WriteableBitmap bmi2 = new
            WriteableBitmap(bmi);
 image1.Source = bmi2;

In this case the WriteableBitmap is created with no problems. If the URI was an HTTP URL, however, the load would not block the execution and the result would be an error.

280 questions
0
votes
1 answer

How to Capture User Signatures on WP7?

Check this out First thing!! so this guy posts how to do this on the blog but it doesn't work. their have been a few people trying to also do the same thing and i know people here could help figure this out. i did realize because it's WP7, You cant…
Keeano
  • 309
  • 8
  • 33
0
votes
2 answers

Save a WriteableBitmap as an image to SharePoint document library

I have a requireemnt in which I have to upload a WriteableBitmap generated as an image in to SharePoint document library. Can anyone please help me ? Thank you.
user318197
  • 333
  • 2
  • 5
  • 25
0
votes
1 answer

Display image in Android's ImageViewer widget using byte array created on .NET

I have a bunch of images stored in my server's database as byte arrays that I'd like to consume in my Android app. The byte arrays were created from images in a Windows Phone 7 app, so using .NET's WriteableBitmap (wbmp) to save to an…
0
votes
1 answer

Loading Image in Silverlight

I want to create a WritableBitmap and display a bitmap from stream onto a Image object. How to do that in Silverlight. I am doing the following which is not working. Image img = new Image(); System.IO.Stream stream = File.OpenRead("1.bmp");…
Nemo
  • 24,540
  • 12
  • 45
  • 61
0
votes
1 answer

WriteableBitmap extension method FillEllipse is creating artifacts on edges of the image

I am using WriteableBitmap with WriteableBitmapEx, specifically FillEllipse method and when I call FillEllipse where portion of the ellipse is drawn outside the image, it causes an artifact on edge of the image. Some code for illustration: public…
Tedd Parsile
  • 65
  • 1
  • 10
0
votes
1 answer

Setting thumbnail of SystemMediaTransportControlsDisplayUpdater

I am Setting thumbnail of SMTC control from stream via SystemMediaTransportControlsDisplayUpdater, but it is not working var response = await new HttpClient().GetAsync(imgUrl); systemMediaTransportControlsDisplayUpdater.Thumbnail =…
Pavan Tiwari
  • 3,077
  • 3
  • 31
  • 71
0
votes
1 answer

C# OpenCV VideoWriter saves in unexpected colors

I am using Intel Realsense RGB camera to show live stream on WPF window as well as save the stream into a file. What I am showing on window has correct colors but when I save it, the video colors are off (more purple). Please see screenshot:…
golu
  • 629
  • 2
  • 7
  • 18
0
votes
1 answer

Pixels shift in WriteableBitmap

I have faced a problem with WriteableBitmap. I am trying to render a 3d cube. But when pixels is being written to WriteableBitmap, part of them just shift. Initialized cube: And that what's happening, when I am trying to rotate it by 45 degrees…
Dmitry
  • 18
  • 3
0
votes
0 answers

C# Type to handle images

I have a system that captures screenshots from different systems and on different ways. These images are used by different clients, e.g. image comparison, OCR, displaying in GUI, logging etc. Currently I designed my interfaces to use BitmapSource.…
Creepin
  • 482
  • 4
  • 20
0
votes
1 answer

WriteableBitmap Copy memory leak

I am working on WriteableBitmaps and I have a method that: Copies WriteableBitmap from parameter to variable that is outside method Works on first bitmap Adds copied bitmap to UndoStack The point of this method is to make changes on bitmap and…
flabbet
  • 175
  • 1
  • 2
  • 6
0
votes
0 answers

How can I update the contents of a TransformedBitmap?

I'm using a TransformedBitmap in my WPF application to stretch a WriteableBitmap. I need to update the WriteableBitmap and then transform it as the user moves a slider control. Currently I'm instantiating a new TransformedBitmap every time the…
LKeene
  • 627
  • 1
  • 8
  • 22
0
votes
1 answer

WriteableBitmap in .NET Standard 2.0

I have a working ASP.NET WebAPI which processes images, I'm trying to port the API over to Azure Functions (.NET Standard 2.0). I was able to migrate most of the functionality except one piece. I'm using WriteableBitmap to perform some manipulations…
nor0x
  • 1,213
  • 1
  • 15
  • 41
0
votes
1 answer

How to draw directly on an Image?

I've a little program to draw in pixels. It actually works fine, but every time it updates the image via my timer, I notice a flicker. I think that's due to always setting a new source, so my question is: if there is a way to draw directly on the…
TheMadGuy
  • 97
  • 6
0
votes
0 answers

Pixel by Pixel color conversion using WriteableBitmap

I am working on a windows application. I want to do a pixel by pixel color change of a PNG from black to white.PNG has a transparent background. For this purpose, I have written a little function, that looks like this: public void…
Rachel
  • 133
  • 1
  • 16
0
votes
1 answer

WriteableBitmap set pixels

I am using WPF and i would like to manipulate some pixels of my image. I am using WritableBitmap because i can use it indirect from source. When i try to set some pixels RGB values (in order), the result is not that i expected. I use this extension…
Péter Hidvégi
  • 743
  • 6
  • 21