system.drawing.imaging

Grey borders in DrawImage (.NET system.drawing.drawing2D)

浪尽此生 提交于 2020-07-30 08:12:59
问题 I'm trying to create an image on a bitmap using C#. Somehow it always adds grey border on all sides of the image. Many questions have been posted with the solution and I have tried almost all of them but none of them worked. Code that I'm using: Bitmap appearance = new Bitmap(490, 196, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(appearance)) { graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.AntiAlias;

C# Drawing.Imaging dropping GIF frames if they are identical

隐身守侯 提交于 2020-01-14 05:54:25
问题 I need to load GIF animations and convert them frame by frame to bitmaps. To do that, I am extracting my GIF file frame by frame using Drawing.Imaging library and then casting each frame to bitmap. Everything works just fine except the times when the consecutive frames are the same, when there is no pixel difference. The library seems to be dropping such frames. I came to that conslusion with a simple test. I have created an animation of a circle that is growing and shrinking with a pause

What does `Encoder.ScanMethod` do?

烈酒焚心 提交于 2019-12-13 04:18:32
问题 One of the params which can be used when saving a bitmapis Encoder.ScanMethod . It is documented here at least in theory: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.encoder.scanmethod But the page says nothing at all about what it actually does . The docs just talk about EncoderParameters in general (and is the same boilerplate text as for other parameters, some of which are also poorly documented). 来源: https://stackoverflow.com/questions/55384173/what-does-encoder

What does `Encoder.RenderMethod` do?

…衆ロ難τιáo~ 提交于 2019-12-13 03:32:39
问题 Encoder.RenderMethod is one of the params which can be used when saving a bitmap, etc. It is nominally documented here: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.encoder.rendermethod But the page says nothing at all about what it actually does . It just talks about EncoderParameters in general (and is the same boilerplate text as for other parameters, some of which are also poorly documented). Thanks 来源: https://stackoverflow.com/questions/55384129/what-does-encoder

What does `Encoder.Version` do?

孤街浪徒 提交于 2019-12-12 01:02:27
问题 Encoder.Version is one of the EncoderParameters which can be specified for e.g., saving a bitmap. However it is essentially undocumented as far as I can tell. The documentation that does exist: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.encoder.version actually has the wrong text in the remarks section. So, what does this parameter do? Thanks 来源: https://stackoverflow.com/questions/55384078/what-does-encoder-version-do

Error: The calling thread cannot access this object because a different thread owns it

雨燕双飞 提交于 2019-12-02 07:08:49
问题 I get this error. Here is the code: Image image; BitmapImage BmpImg; MemoryStream ms; public void Convert() { ms = new MemoryStream(); image.Save(ms, ImageFormat.Jpeg); BmpImg = new BitmapImage(); BmpImg.BeginInit(); BmpImg.StreamSource = new MemoryStream(ms.ToArray()); BmpImg.EndInit(); } private void Btn_Click(object sender, RoutedEventArgs e) { Dispatcher.Invoke(new Action(() => { Image.Source = BmpImg; })); } How to convert a System.Drawing.Image to BitmapImage and display the same on wpf

Reading/preserving a PixelFormat.Format48bppRgb PNG Bitmap in .NET?

旧时模样 提交于 2019-12-02 01:44:10
问题 I've been able to create a Format48bppRgb .PNG file (from some internal HDR data) using the the following C# code: Bitmap bmp16 = new Bitmap(_viewer.Width, _viewer.Height, System.Drawing.Imaging.PixelFormat.Format48bppRgb); System.Drawing.Imaging.BitmapData data16 = bmp16.LockBits(_viewer.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp16.PixelFormat); unsafe { (populates bmp16) } bmp16.Save( "C:/temp/48bpp.png", System.Drawing.Imaging.ImageFormat.Png ); ImageMagik (and

Determine if Alpha Channel is Used in an Image

佐手、 提交于 2019-11-27 23:38:41
As I'm bringing in images into my program, I want to determine if: they have an alpha-channel if that alpha-channel is used #1 is simple enough with using Image.IsAlphaPixelFormat . For #2 though, other than looping through every single pixel, is there a simple way I can determine if at least one of the pixels has an alpha channel that is used (i.e. set to some other value than 255 )? All I need back is a boolean and then I'll make determination as to whether to save it out to 32-bit or 24-bit. UPDATE : I have discovered that ImageFlags.HasTranslucent should provide me with what I'm looking

What quality level does Image.Save() use for jpeg files?

余生长醉 提交于 2019-11-27 08:13:52
I just got a real surprise when I loaded a jpg file and turned around and saved it with a quality of 100 and the size was almost 4x the original. To further investigate I open and saved without explicitly setting the quality and the file size was exactly the same. I figured this was because nothing changed so it's just writing the exact same bits back to a file. To test this assumption I drew a big fat line diagonally across the image and saved again without setting quality (this time I expected the file to jump up because it would be "dirty") but it decreased ~10Kb! At this point I really don

Determine if Alpha Channel is Used in an Image

若如初见. 提交于 2019-11-26 23:14:49
问题 As I'm bringing in images into my program, I want to determine if: they have an alpha-channel if that alpha-channel is used #1 is simple enough with using Image.IsAlphaPixelFormat . For #2 though, other than looping through every single pixel, is there a simple way I can determine if at least one of the pixels has an alpha channel that is used (i.e. set to some other value than 255 )? All I need back is a boolean and then I'll make determination as to whether to save it out to 32-bit or 24