bitmapsource

How to get the image format from Clipboard class?

≡放荡痞女 提交于 2020-01-15 11:20:08
问题 I'm making a image viewer in C#. that feature is copy and paste function using Clipboard class on C#. And I succeeded to get image of BitmapSource. but it can not check image formats (jpeg, png, bmp). This is supported source from C# BitmapSource source = Clipboard.GetImage(); These are what i want to use. byte[] image = Clipboard.GetImage("image/png") byte[] image = Clipboard.GetImage("image/bmp") I will say, How do I check image format from BitmapSource or Clipboard? 回答1: Simply put, you

How to get the image format from Clipboard class?

谁说我不能喝 提交于 2020-01-15 11:19:07
问题 I'm making a image viewer in C#. that feature is copy and paste function using Clipboard class on C#. And I succeeded to get image of BitmapSource. but it can not check image formats (jpeg, png, bmp). This is supported source from C# BitmapSource source = Clipboard.GetImage(); These are what i want to use. byte[] image = Clipboard.GetImage("image/png") byte[] image = Clipboard.GetImage("image/bmp") I will say, How do I check image format from BitmapSource or Clipboard? 回答1: Simply put, you

WPF: How to rotate a BitmapSource by any angle

北城以北 提交于 2020-01-07 03:55:21
问题 Ok, I tried this: TransformedBitmap tbm = new TransformedBitmap(myBitmapSource, new RotateTransform(angle)); return tbm; But this does not work with angles other than multiples of 90degrees. New I tried to use a RenderTargetBitmap: var image = new Canvas(); image.Width = myBitmapSource.PixelWidth; image.Height = myBitmapSource.PixelHeight; image.Background = new ImageBrush(myBitmapSource); image.RenderTransform = new RotateTransform(angle); RenderTargetBitmap rtb = new RenderTargetBitmap

ArgumentException not caught when using BitmapImage.BeginInit()

天大地大妈咪最大 提交于 2020-01-06 07:06:36
问题 Why when an ArgumentException occurs because image.jpg has an invalid metadata header does the first example catch the exception, and the second example does not? Example 1: try { Uri myUri = new Uri("http://example.com/image.jpg", UriKind.RelativeOrAbsolute); JpegBitmapDecoder decoder2 = new JpegBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource2 = decoder2.Frames[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); }

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

≡放荡痞女 提交于 2019-12-28 02:05:09
问题 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 the OutOfMemoryException. Here are the steps I am currently taking to try to solve this: 1)I am removing the BitmapSource objects from the app 2)I am setting

Remove alpha from a BitmapSource

南楼画角 提交于 2019-12-24 13:32:18
问题 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: (source: umbc.edu) It's gray because the background of the window it's on is gray. Whatever background I give the window will show through. How can I get the captured image to more accurately reflect the original?

Why this Bitmap Image changes its size after I load it?

瘦欲@ 提交于 2019-12-23 12:05:46
问题 Quick question: I have this 1000 x 1000 bitmap image: and I use this routine to load it: private BitmapSource initialBitmap = new BitmapImage(new Uri("C:\\Users\\...\\Desktop\\Original.bmp")); Why after I load it, and right after I step over the above line, I see it as 800 x 800 ? P.S I want it to be 1000 x 1000 and without using any Resize functions. It was working and suddenly it is 800*800 ! 回答1: The values returned by BitmapSource.Width and BitmapSource.Height are not in pixels, but

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

时间秒杀一切 提交于 2019-12-23 07:40:58
问题 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: <Window.Resources> <Image x:Key="Off1" Source="/WPFApplication;component/Images/off_button.png" Height="30" Width="70" /> <Image x:Key="On1" Source="/WPFApplication;component/Images/on_button.png" Height="30" Width="70"/> </Window.Resources> And the event code is, "flag"

Convert BitmapSource to MemoryStream

给你一囗甜甜゛ 提交于 2019-12-22 18:20:13
问题 How Do I convert BitmapSource to MemoryStream. Though I tried some code: private Stream StreamFromBitmapSource(BitmapSource writeBmp) { Stream bmp; using (bmp = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(writeBmp)); enc.Save(bmp); } return bmp; } It doesn't give any error but after putting debugging point it is showing some exceptions which are listed below. Capacity: 'printStream.Capacity' threw an exception of type 'System

Saving BitmapSource as Tiff encoded JPEG using Libtiff.net

孤人 提交于 2019-12-22 14:48:23
问题 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,