gdi+

How to disable subsampling with .NET / GDI+?

落花浮王杯 提交于 2019-12-09 13:25:04
问题 I am trying to save a JPEG image using the Bitmap class. I noticed that sharp edges were always blury regardless of the quality level that I specify. I figured out that it is due to subsampling of one or more of the channels. How do I disable subsampling when saving the image? I am currently using this code: EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L); ImageCodecInfo codec = GetEncoderInfo("image/jpeg"); image.Save

Win32: Does a window have the same HDC for its entire lifetime?

与世无争的帅哥 提交于 2019-12-09 06:28:52
问题 Am i allowed to use a DC outside of a paint cycle? Is my window's DC guaranteed to be valid forever? i'm trying to figure out how long my control's Device Context (DC) is valid. i know that i can call: GetDC(hWnd); to get the device context of my control's window, but is that allowed? When Windows sends me a WM_PAINT message, i am supposed to call BeginPaint/EndPaint to properly acknowledge that i've painted it, and to internally clear the invalid region: BeginPaint(hWnd, {out}paintStruct);

SecurityException when calling Graphics.DrawImage

大憨熊 提交于 2019-12-09 03:26:43
问题 I'm deploying an MVC3 app that stores images in a database. The requirement is to do a GET to retrieve the image from the database and then write the image into the response stream. All is working great locally (of course). I'm using a shared hosting provider (and yes, no Full trust, <trust> is blocked). I am using this ImageResult to return the image: public override void ExecuteResult(ControllerContext context) { using (Bitmap bitmap = new Bitmap(width, height)) { using (Graphics graphics =

GDI+ exception saving a Bitmap to a MemoryStream

假如想象 提交于 2019-12-09 01:36:47
问题 I have a problem in a Windows Forms application with Bitmap.Save failing when I save to a MemoryStream. The problem only seems to occur intermittently on one machine (so far) and the bad news it is at a customer site. I can't debug on the machine, but I got a stack trace that narrowed the problem down to a single line of code. Here's a condensed version of my code: byte[] ConvertPixelsToBytes() { // imagine a picture class that creates a 24 bbp image, and has // a method to get an unmanaged

Converting from a Format8bppIndexed to a Format24bppRgb in C#/GDI+

二次信任 提交于 2019-12-08 19:32:20
问题 Alright, I have an image coming through from an external application in an 8-bit indexed format. I need this image converted to a 24-bit format of the exact same size. I've tried creating a new Bitmap of the same size and of type Format24bppRgb and then using a Graphics object to draw the 8-bit image over it before saving it as a Bmp. This approach doesn't error out but when I open the resulting image the BMP header has all kinds of funky values. The height and width are HUGE and, in addition

GDI+ Bug: Anti-Aliasing White On Transparency

落爺英雄遲暮 提交于 2019-12-08 18:49:29
The following code will create a transparent bitmap and then draw a white ellipse on it with anti-aliasing. using(var background = new Bitmap(500, 500)) using (var graphics = Graphics.FromImage(background)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.Clear(Color.Transparent); graphics.DrawEllipse(new Pen(Color.White, 50), 250, 250, 150, 150); background.Save("test.png", ImageFormat.Png); } The bug I have found is that the anti-aliased pixels around the edge of the ellipse have an unexpected color. They have RGB values of (254,254,254) instead of (255,255,255). Since GDI+

Translating a Point(X,Y) for Images of Different Sizes from a Custom PictureBox Control

瘦欲@ 提交于 2019-12-08 14:00:33
问题 I have to process several images in bulk.I have to place some text at a particular point(X, Y).There is a custom control that is derived from picturebox that allows the user to drag the text and place it at the desired location. There are two types of images for which I set the PictureBoxSizeMode differently Vertical Images I set > PictureBoxSizeMode.Zoom; Horizontal For Horizontal Images that fill up the PictureBox i set > PictureBoxSizeMode.StretchImage The user can select the location to

Changing co-ordinate system

若如初见. 提交于 2019-12-08 13:18:49
问题 I need to switch from the XY co-ordinate system shown above to the X'Y' co-ordinate system using System::Drawing::Drawing2D (i.e. GDI+). This is what I have in mind: float rotation = // +90 below is because AB is the new vertical... Math::Atan2(pB.Y - pA.Y, pB.X - pA.X) * 180.0 / Math::PI + 90.0f; Matrix m; m.Translate(pA.X, pA.Y); m.Rotate(rotation); m.Invert(); array<PointF> points = gcnew array<PointF>{ pC }; m.TransformPoints(points); Is there a way to do this while minimizing rounding

C# Bitmap created programmatically; crop code started giving “A generic error occurred in GDI+”

十年热恋 提交于 2019-12-08 09:10:16
问题 I have the following method that renders text into an image. It makes a larger than necessary bitmap, draws the text, then hunts the bitmap for blank space and crops it off. At the point where the image is saved, it throws the error "A generic error occurred in GDI+". This code has always worked on this same machine, that I develop on, though it hasn't been run in a long time so a reasonable amount of windows updates are likely to have occurred since the last time it worked. Nothing else has

Updating EXIF info in image files

♀尐吖头ヾ 提交于 2019-12-08 07:07:03
问题 I need to update EXIF info in a lot of .png files (tens of thousands of hires pictures) and I wonder if there is some (not too complicated and documented) way that I can do that without opening (decompressing the whole image) and then re-save it (compressing it again)? 回答1: Unfortunately the .Net GDI+ image format support is very patchy. Consider ImageMagick. There is a .Net wrapper for it. http://www.imagemagick.org/script/index.php Also consider ExifTool: http://owl.phy.queensu.ca/~phil