writeablebitmap

How can I convert WriteableBitmap to BitmapImage?

会有一股神秘感。 提交于 2019-11-29 09:25:05
BitmapImage bitmapImage = new BitmapImage(new Uri("arka_projects_as_logo.png", UriKind.Relative)); Image uiElement = new Image() { Source = bitmapImage }; ScaleTransform t = new ScaleTransform() { ScaleX = 0.2, ScaleY = 0.2 }; WriteableBitmap writeableBitmap = new WriteableBitmap(uiElement,t); I want to insert the result of this conversions (writeableBitmap) into System.Windows.Controls.Image. When I do this: Image arkaImage = new Image() { Source = writeableBitmap }; arkaImage isn't shown at all. What can be done to make it work? WriteableBitmap wb = .. using (MemoryStream ms = new

Calculating the required buffer size for the WriteableBitmap.WritePixels method

北城以北 提交于 2019-11-29 09:16:59
How do I calculate the required buffer size for the WriteableBitmap.WritePixels method? I am using the overload taking four parameters, the first is an Int32Rect, the next is a byte array containing the RGBA numbers for the colour, the third is the stride (which is the width of my writeable bitmap multiplied by the bits per pixel divided by 8), and the last is the buffer (referred to as the offset in Intellisense). I am getting the Buffer size is not sufficient runtime error in the below code: byte[] colourData = { 0, 0, 0, 0 }; var xCoordinate = 1; var yCoordinate = 1; var width = 2; var

Converting WriteableBitmap to Bitmap in C#

╄→尐↘猪︶ㄣ 提交于 2019-11-29 00:30:01
Is there any way for converting WriteableBitmap to Bitmap in C# ? red_sky It's pretty straightforward, actually. Here's some code that should work. I haven't tested it and I'm writing it from the top of my head. private System.Drawing.Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp) { System.Drawing.Bitmap bmp; using (MemoryStream outStream = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create((BitmapSource)writeBmp)); enc.Save(outStream); bmp = new System.Drawing.Bitmap(outStream); } return bmp; } The WriteableBitmap inherits from a

WPF window image updating from menuitem but not when in while loop

家住魔仙堡 提交于 2019-11-28 10:32:31
问题 Okay, this is a real head-scratcher: If I select a menuitem that causes the image, that makes up the entire window (a writeableBitmap) to have some pixels drawn on it, it does so and displays correctly. However, if I add a while loop (let's say for 5 loops) to the same method the drawing on the bitmap DOES NOT DISPLAY until the loop is completed and then the 5th redrawn bitmap is correctly displayed. So, is there some sort of 'automatic refresh' that is happening to the window when a menuitem

How can I render text on a WriteableBitmap on a background thread, in Windows Phone 7?

隐身守侯 提交于 2019-11-28 04:35:18
I am trying to render text on a bitmap in a Windows Phone 7 application. Code that looks more or less like the following would work fine when it's running on the main thread: public ImageSource RenderText(string text, double x, double y) { var canvas = new Canvas(); var textBlock = new TextBlock { Text = text }; canvas.Children.Add(textBloxk); Canvas.SetLeft(textBlock, x); Canvas.SetTop(textBlock, y); var bitmap = new WriteableBitmap(400, 400); bitmap.Render(canvas, null); bitmap.Invalidate(); return bitmap; } Now, since I have to render several images with more complex stuff, I would like to

Save WriteableBitmap to file using WPF

瘦欲@ 提交于 2019-11-28 02:46:42
问题 I have: WriteableBitmap bmp; I basicly want to save it into a file on the disk like the following: C:\bmp.png I read some forums which mentions to read: bmp.Pixels and save those pixels into a Bitmap then use Bitmap.SaveImage() function. However, I can't access any Pixels . Apperantly my WriteableBitmap does not have any property named Pixels . I use .NET Framework 4.0. 回答1: Use your WriteableBitmap's clone and use this function as below: CreateThumbnail(filename, _frontBitmap.Clone()); ...

Calculating the required buffer size for the WriteableBitmap.WritePixels method

陌路散爱 提交于 2019-11-28 02:40:21
问题 How do I calculate the required buffer size for the WriteableBitmap.WritePixels method? I am using the overload taking four parameters, the first is an Int32Rect, the next is a byte array containing the RGBA numbers for the colour, the third is the stride (which is the width of my writeable bitmap multiplied by the bits per pixel divided by 8), and the last is the buffer (referred to as the offset in Intellisense). I am getting the Buffer size is not sufficient runtime error in the below code

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

谁说胖子不能爱 提交于 2019-11-28 01:56:14
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? 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 ConvertWriteableBitmapToBitmapImage(WriteableBitmap wbm) { BitmapImage bmImage = new

Converting WriteableBitmap to Bitmap in C#

跟風遠走 提交于 2019-11-27 15:21:09
问题 Is there any way for converting WriteableBitmap to Bitmap in C# ? 回答1: It's pretty straightforward, actually. Here's some code that should work. I haven't tested it and I'm writing it from the top of my head. private System.Drawing.Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp) { System.Drawing.Bitmap bmp; using (MemoryStream outStream = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create((BitmapSource)writeBmp)); enc.Save(outStream)

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