bitmapsource

Copying from BitmapSource to WritableBitmap

ⅰ亾dé卋堺 提交于 2019-12-21 04:20:49
问题 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, bmp.Palette); row.Lock(); bmp.CopyPixels(new Int32Rect(top, 0, bmp.PixelWidth, bottom - top), row.BackBuffer, row.PixelHeight * row.BackBufferStride, row.BackBufferStride); row.AddDirtyRect(new Int32Rect(0, 0, row.PixelWidth, row.PixelHeight)); row.Unlock(); I get

Clean up a collection of BitmapSource

寵の児 提交于 2019-12-14 03:19:13
问题 i have a collection of BitmapSource that are created by setting its StreamSource property to a MemoryStream of byte array. How do i remove them from memory after using them? thanks! 回答1: Just clear your references to them, the garbage collector will take care of reclaiming the memory. 来源: https://stackoverflow.com/questions/11950081/clean-up-a-collection-of-bitmapsource

Is it possible to convert a byte[] to a bitmapsource?

你说的曾经没有我的故事 提交于 2019-12-13 05:14:20
问题 So far I have: using (MemoryStream ms = new MemoryStream(imageData)) { Bitmap img = (Bitmap)Image.FromStream(ms); } And then I would imagine I would be able to get a BitmapSource from img somehow? If this is totally wrong please feel free to correct me. 回答1: Try using BitmapSource.Create(). But you need to create pallete first: var colors = new List<Color>(); colors.Add(Colors.Red); colors.Add(Colors.Blue); colors.Add(Colors.Green); var palette = new BitmapPalette(colors); 回答2: Got the

Get file Thumbnail image with transparency

空扰寡人 提交于 2019-12-13 04:32:14
问题 I want to get file's thumbnail with transparency. I have the following code to achieve it: BitmapImage GetThumbnail(string filePath) { ShellFile shellFile = ShellFile.FromFilePath(filePath); BitmapSource shellThumb = shellFile.Thumbnail.ExtraLargeBitmapSource; Bitmap bmp = new Bitmap(shellThumb.PixelWidth, shellThumb.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),

How to properly use Image as ToolTip?

£可爱£侵袭症+ 提交于 2019-12-11 11:04:43
问题 I have a BitmapSource 1690x214 (taken from an EMF file using this code), and I want to use this image as ToolTip . This is the image displayed using Paint: So i wrote this code: BitmapSource bmp = myBitmapSource; // "Dk01Light.EMF" Image img = new Image() { Source = bmp, Width = bmp.Width, Height = bmp.Height, Stretch = Stretch.Uniform, }; myTooltip = img; And this is the result: As you can see, the right and bottom margin are completly different. Why? How can i fix this problem? 回答1: It

Display Image from Byte Array in WPF - Memory Issues

半世苍凉 提交于 2019-12-11 05:04:31
问题 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 RealImage - Has no setter, the byte array converted to a bitmap source, this is shown in a tooltip when the user hovers over it. The issue I have is that if a user hovers

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

耗尽温柔 提交于 2019-12-10 13:29:38
问题 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 to be printing the image? 回答1: DPI does not affect the pixels of a bitmap in any way. The DPI of an image is just attached metadata that is a measurement used to describe how large in real-world measurements is each pixel supposed to be. For example

How to read pixels in four corners of a BitmapSource?

不问归期 提交于 2019-12-07 10:27:40
问题 I have a .NET BitmapSource object. I would like to read the four pixels in corners of the bitmap, and test whether all of them are darker than white. How can I do that? Edit: I wouldn't mind converting this object to another type with a better API. 回答1: BitmapSource has a CopyPixels method that can be used to get one or more pixel values. A helper method that gets a single pixel value at a given pixel coordinate may look like shown below. Note that it perhaps has to be extended to support all

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

孤者浪人 提交于 2019-12-07 02:15:35
问题 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? 回答1: public static BitmapSource BitmapSourceFromBrush(Brush drawingBrush, int size = 32, int dpi = 96) { // RenderTargetBitmap = builds a bitmap rendering of a visual var pixelFormat = PixelFormats.Pbgra32; RenderTargetBitmap rtb = new RenderTargetBitmap(size, size, dpi, dpi, pixelFormat); // Drawing visual allows us to

Saving BitmapSource as Tiff encoded JPEG using Libtiff.net

孤街醉人 提交于 2019-12-06 11:49:55
I'm trying to write a routine that will save a WPF BitmapSource as a JPEG encoded TIFF using LibTiff.net. Using the examples provided with LibTiff I came up with the following: private void SaveJpegTiff(BitmapSource source, string filename) { if (source.Format != PixelFormats.Rgb24) source = new FormatConvertedBitmap(source, PixelFormats.Rgb24, null, 0); using (Tiff tiff = Tiff.Open(filename, "w")) { tiff.SetField(TiffTag.IMAGEWIDTH, source.PixelWidth); tiff.SetField(TiffTag.IMAGELENGTH, source.PixelHeight); tiff.SetField(TiffTag.COMPRESSION, Compression.JPEG); tiff.SetField(TiffTag