gdi+

Generic GDI+ Error

大憨熊 提交于 2019-12-11 01:38:16
问题 I get as Generic GDI Error with the following code. Usually it complies and executes just fine but sometimes fails with a Generic GDI+ Error. Is there some way to solve the issue, or a way to take a screenshot without using inter-op? Public Function CopyImageFromScreen(region as Int32Rect) As BitmapSource Dim img As New System.Drawing.Bitmap(region.Width, region.Height) Dim gfx As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img) gfx.CopyFromScreen(region.X, region.Y, 0, 0, New

Why am I getting a black background around my images when resizing even when Bitmap is set to Graphics.Clear(Color.Transparent)

笑着哭i 提交于 2019-12-11 01:30:05
问题 I'm building an Image upload tool that resizes an image to fit a fixed size but it's adding a black background instead of a transparent one to the filler space around the image. I've read that the Bitmap needs to be set to a PixelFormat with an Alpha layer and that I can set the Graphics clear colour to transparent but I'm still getting the same problem. My images are mostly jpegs. Here is the code: private void ResizeImage(Image Original, Int32 newWidth, Int32 newHeight, String pathToSave) {

How to overlap two controls

别说谁变了你拦得住时间么 提交于 2019-12-11 01:25:20
问题 I have a Circle and a Line control. Circle control's OnPaint draws a circle and Line control's one draws a line. These two controls are contained in another control (DrawingControl). I need to put a Line over a Circle, but Circle's background deletes the Line. I tried enabling transparency and overriding Circle's OnPaintBackground method, but it doesn't seem to work. Do you have any ideas? Thanks. 回答1: Does this tutorial help? It consists of three steps: Enabling transparency, overriding

Resize PNG image without losing color data from fully transparent pixels

做~自己de王妃 提交于 2019-12-11 01:02:23
问题 I've been trying to figure out a way to resize a PNG image without losing color data from pixels that are completely transparent. Here is the code that I'm using to achieve this: //sourceImage is also a bitmap read in earlier using (var scaledBitmap = new Bitmap(desiredWidth, desiredHeight, PixelFormat.Format32bppArgb)){ using (var g = Graphics.FromImage(scaledBitmap)){ var attr = new ImageAttributes(); attr.SetWrapMode(WrapMode.TileFlipXY); g.CompositingQuality = CompositingQuality

convert png to gif with gdi+ (C#)

烂漫一生 提交于 2019-12-11 00:07:33
问题 i have a png file which must be converted to a gif file. There is a transparent part in it, and when i save it the transparent part is black in stead of transparent. here's my code: FileStream imgStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write); Image.FromFile(imageInput).Save(imgStream, ImageFormat.Gif); here, imageinput is the fullpath to my png, and output file is the filefullpath with .gif extension. can you see what is wrong here? michel 回答1: PNG uses alpha

Rotate Hue using ImageAttributes in C#

我只是一个虾纸丫 提交于 2019-12-10 23:27:57
问题 How can I rotate the hue of an image using GDI+'s ImageAttributes (and presumably ColorMatrix )? Note that I want to rotate the hue, not tint the image. EDIT : By rotating the hue, I mean that each color in the image should be shifted to a different color, as opposed to making the entire image a shade of one color. For example, Original:http://www.codeguru.com/img/legacy/gdi/Tinter03.jpg Rotated: http://www.codeguru.com/img/legacy/gdi/Tinter15.jpg or http://www.codeguru.com/img/legacy/gdi

Parameter is not valid when saving TIFF to stream

纵饮孤独 提交于 2019-12-10 21:48:30
问题 I have a multi-page TIFF that I'm splitting up page by page using Leadtools, and changing the compression on them to be compatible with a third party. When I try to save the image to a memoryStream, I get a Parameter is not valid exception. However, this only happens on their machine, or my test machine running Server 2008. I cannot reproduce this on my development machine (Win 7 using VS2008). Here is the code: RasterImage image = codecs.Load( file, 0, CodecsLoadByteOrder.RgbOrGray,

Bitmap.Save “Object is currently in use elsewhere” Threading Issue

前提是你 提交于 2019-12-10 20:46:34
问题 I have some code like this: public void SaveImage(int Counter) { var task = Task.Factory.StartNew(() => { var image = FinalImage; if (image != null) { image.Save(FinalImageSaveLocation + "test" + Counter + ".bmp"); } }, TaskCreationOptions.PreferFairness); } I have a for loop creating x amount of images using similar code below: for(int i = 0; i < 100; i++) { Pencil.DrawImage(image, x, y); //Pencil is created at a initialisation stage SaveImage(i); //by Pencil = Graphics.FromImage(FinalImage)

Apply ScaleTransform to Graphics GDI+

孤街醉人 提交于 2019-12-10 19:17:23
问题 I have put this simple code together to draw a line. Now I want to apply a ScaleTransform to it by a factor of 10; but the code below doesn't work. var bitmap = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height); var g = Graphics.FromImage(bitmap); pictureBox1.Image = bitmap; var pn = new Pen(Color.Wheat, -1); g.DrawLine(pn, 0, 0, 10, 10); pn.Dispose(); // I'm trying to scaletransform here! g.ScaleTransform(10, 10); Update: What is the correct way to update the changes? I'm not

System.Drawing.Image.Save throws ExternalException: A generic error occurred in GDI

你离开我真会死。 提交于 2019-12-10 17:17:03
问题 I have function which takes a bitmap, copies part of it and saves it as 8bpp tiff. Filename of the result image is unique and file doesn't exist, program has permission to write to the target folder. void CropImage(Bitmap map) { Bitmap croped = new Bitmap(200, 50); using (Graphics g = Graphics.FromImage(croped)) { g.DrawImage(map, new Rectangle(0, 0, 200, 50), ...); } var encoderParams = new EncoderParameters(2); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder