Search Results

Search found 296 results on 12 pages for 'gdi'.

Page 4/12 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • GDI+ & Delphi, PNG resource, DrawImage, ColorConversion -> Out of Memory

    - by Paul
    I have started to toy around with GDI+ in Delphi 2009. Among the things that I wanted to do was to load a PNG resource and apply a Color Conversion to it when drawing it to the Graphics object. I am using the code provided in http://www.bilsen.com/gdiplus/. To do that I just added a new constructor to TGPBitmap that uses the same code found in <www.codeproject.com>/KB/GDI-plus/cgdiplusbitmap.aspx (C++) or <www.masm32.com>/board/index.php?topic=10191.0 (MASM) converted to Delphi. For reference, the converted code is as follows: constructor TGPBitmap.Create(const Instance: HInst; const PngName: String; dummy : PngResource_t); const cPngType : string = 'PNG'; var hResource : HRSRC; imageSize : DWORD; pResourceData : Pointer; hBuffer : HGLOBAL; pBuffer : Pointer; pStream : IStream; begin inherited Create; hResource := FindResource(Instance, PWideChar(PngName), PWideChar(cPngType)); if hResource = 0 then Exit; imageSize := SizeofResource(Instance, hResource); if imageSize = 0 then Exit; pResourceData := LockResource(LoadResource(Instance, hResource)); if pResourceData = nil then Exit; hBuffer := GlobalAlloc(GMEM_MOVEABLE, imageSize); if hBuffer <> 0 then begin try pBuffer := GlobalLock(hBuffer); if pBuffer <> nil then begin try CopyMemory(pBuffer, pResourceData, imageSize); if CreateStreamOnHGlobal(hBuffer, FALSE, pStream) = S_OK then begin GdipCheck(GdipCreateBitmapFromStream(pStream, FNativeHandle)); end; finally GlobalUnlock(hBuffer); pStream := nil; end; end; finally GlobalFree(hBuffer); end; end; end; The code seems to work fine as I am able to draw the loaded image without any problems. However, if I try to apply a Color Conversion when drawing it, then I get a lovely error: (GDI+ Error) Out of Memory. If I load the bitmap from a file, or if I create a temporary to which I draw the initial bitmap and then use the temporary, then it works just fine. What bugs me is that if I take the C++ project from codeproject, add the same PNG as resource and use the same color conversion (in other words, do the exact same thing I am doing in Delphi in the same order and with the same function calls that happen to go to the same DLL), then it works. The C++ code looks like this: const Gdiplus::ColorMatrix cTrMatrix = { { {1.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.5, 0.0}, {0.0, 0.0, 0.0, 0.0, 1.0} } }; Gdiplus::ImageAttributes imgAttrs; imgAttrs.SetColorMatrix(&cTrMatrix, Gdiplus::ColorMatrixFlagsDefault, Gdiplus::ColorAdjustTypeBitmap); graphics.DrawImage(*pBitmap, Gdiplus::Rect(0, 0, pBitmap->m_pBitmap->GetWidth(), pBitmap->m_pBitmap->GetHeight()), 0, 0, pBitmap->m_pBitmap->GetWidth(), pBitmap->m_pBitmap->GetHeight(), Gdiplus::UnitPixel, &imgAttrs); The Delphi counterpart is: const cTrMatrix: TGPColorMatrix = ( M: ((1.0, 0.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 0.5, 0.0), (0.0, 0.0, 0.0, 0.0, 1.0))); var lImgAttrTr : IGPImageAttributes; lBitmap : IGPBitmap; begin // ... lImgAttrTr := TGPImageAttributes.Create; lImgAttrTr.SetColorMatrix(cTrMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap); aGraphics.DrawImage ( lBitmap, TGPRect.Create ( 0, 0, lBitmap.Width, lBitmap.Height ), 0, 0, lBitmap.Width, lBitmap.Height, UnitPixel, lImgAttrTr ); I am completely clueless as to what may be causing the issue, and Google has not been of any help. Any ideas, comments and explanations are highly appreciated.

    Read the article

  • Drawing a TextBox in an extended Glass Frame (C# w/o WPF)

    - by Lazlo
    I am trying to draw a TextBox on the extended glass frame of my form. I won't describe this technique, it's well-known. Here's an example for those who haven't heard of it: http://www.danielmoth.com/Blog/Vista-Glass-In-C.aspx The thing is, it is complex to draw over this glass frame. Since black is considered to be the 0-alpha color, anything black disappears. There are apparently ways of countering this problem: drawing complex GDI+ shapes are not affected by this alpha-ness. For example, this code can be used to draw a Label on glass (note: GraphicsPath is used instead of DrawString in order to get around the horrible ClearType problem): public class GlassLabel : Control { public GlassLabel() { this.BackColor = Color.Black; } protected override void OnPaint(PaintEventArgs e) { GraphicsPath font = new GraphicsPath(); font.AddString( this.Text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size, Point.Empty, StringFormat.GenericDefault); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.FillPath(new SolidBrush(this.ForeColor), font); } } Similarly, such an approach can be used to create a container on the glass area. Note the use of the polygons instead of the rectangle - when using the rectangle, its black parts are considered as alpha. public class GlassPanel : Panel { public GlassPanel() { this.BackColor = Color.Black; } protected override void OnPaint(PaintEventArgs e) { Point[] area = new Point[] { new Point(0, 1), new Point(1, 0), new Point(this.Width - 2, 0), new Point(this.Width - 1, 1), new Point(this.Width -1, this.Height - 2), new Point(this.Width -2, this.Height-1), new Point(1, this.Height -1), new Point(0, this.Height - 2) }; Point[] inArea = new Point[] { new Point(1, 1), new Point(this.Width - 1, 1), new Point(this.Width - 1, this.Height - 1), new Point(this.Width - 1, this.Height - 1), new Point(1, this.Height - 1) }; e.Graphics.FillPolygon(new SolidBrush(Color.FromArgb(240, 240, 240)), inArea); e.Graphics.DrawPolygon(new Pen(Color.FromArgb(55, 0, 0, 0)), area); base.OnPaint(e); } } Now my problem is: How can I draw a TextBox? After lots of Googling, I came up with the following solutions: Subclassing the TextBox's OnPaint method. This is possible, although I could not get it to work properly. It should involve painting some magic things I don't know how to do yet. Making my own custom TextBox, perhaps on a TextBoxBase. If anyone has good, valid and working examples, and thinks this could be a good overall solution, please tell me. Using BufferedPaintSetAlpha. (http://msdn.microsoft.com/en-us/library/ms649805.aspx). The downsides of this method may be that the corners of the textbox might look odd, but I can live with that. If anyone knows how to implement that method properly from a Graphics object, please tell me. I personally don't, but this seems the best solution so far. Thanks!

    Read the article

  • Why is drawing to OnPaint graphics faster than image graphics?

    - by Tesserex
    I'm looking for a way to speed up the drawing of my game engine, which is currently the significant bottleneck, and is causing slowdowns. I'm on the verge of converting it over to XNA, but I just noticed something. Say I have a small image that I've loaded. Image img = Image.FromFile("mypict.png"); We have a picturebox on the screen we want to draw on. So we have a handler. pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint); I want our loaded image to be tiled on the picturebox (this is for a game, after all). Why on earth is this code: void pictureBox1_Paint(object sender, PaintEventArgs e) { for (int y = 0; y < 16; y++) for (int x = 0; x < 16; x++) e.Graphics.DrawImage(image, x * 16, y * 16, 16, 16); } over 25 TIMES FASTER than this code: Image buff = new Bitmap(256, 256, PixelFormat.Format32bppPArgb); // actually a form member void pictureBox1_Paint(object sender, PaintEventArgs e) { using (Graphics g = Graphics.FromImage(buff)) { for (int y = 0; y < 16; y++) for (int x = 0; x < 16; x++) g.DrawImage(image, x * 16, y * 16, 16, 16); } e.Graphics.DrawImage(buff, 0, 0, 256, 256); } To eliminate the obvious, I've tried commenting out the last e.Graphics.DrawImage (which means I don't see anything, but it gets rid a call that isn't in the first example). I've also left in the using block (needlessly) in the first example, but it's still just as blazingly fast. I've set properties of g to match e.Graphics - things like InterpolationMode, CompositingQuality, etc, but nothing I do bridges this incredible gap in performance. I can't find any difference between the two Graphics objects. What gives? My test with a System.Diagnostics.Stopwatch says that the first code snippet runs at about 7100 fps, while the second runs at a measly 280 fps. My reference image is VS2010ImageLibrary\Objects\png_format\WinVista\SecurityLock.png, which is 48x48 px, and which I modified to be 72 dpi instead of 96, but those made no difference either.

    Read the article

  • Having trouble compiling with GDI+ (VC++ 2008)

    - by user146780
    I just simply include gdiplus.h and get all these errors: Warning 32 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Warning 38 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Warning 49 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Warning 55 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Warning 61 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2224 Warning 68 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Warning 74 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2310 Warning 82 warning C4229: anachronism used : modifiers on data are ignored c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2321 Error 112 fatal error C1003: error count exceeds 100; stopping compilation c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 236 Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 74 Error 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 280 Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 280 Error 94 error C2761: '{ctor}' : member function redeclaration not allowed c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 195 Error 102 error C2761: '{ctor}' : member function redeclaration not allowed c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 212 Error 110 error C2761: '{ctor}' : member function redeclaration not allowed c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 231 Error 21 error C2535: 'Gdiplus::Metafile::Metafile(void)' : member function already defined or declared c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 813 Error 23 error C2535: 'Gdiplus::Metafile::Metafile(void)' : member function already defined or declared c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 820 Error 25 error C2535: 'Gdiplus::Metafile::Metafile(void)' : member function already defined or declared c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 829 Error 27 error C2535: 'Gdiplus::Metafile::Metafile(void)' : member function already defined or declared c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 923 Error 16 error C2535: 'Gdiplus::Image::Image(void)' : member function already defined or declared c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 471 Error 4 error C2470: 'IImageBytes' : looks like a function definition, but there is no parameter list; skipping apparent body c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 74 Error 89 error C2448: 'Gdiplus::Metafile::{ctor}' : function-style initializer appears to be a function definition c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 76 Error 97 error C2447: '{' : missing function header (old-style formal list?) c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 199 Error 105 error C2447: '{' : missing function header (old-style formal list?) c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 218 Error 2 error C2440: 'initializing' : cannot convert from 'const char [37]' to 'int' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 74 Error 72 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2310 Error 76 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2310 Error 80 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2321 Error 84 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2321 Error 92 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 195 Error 100 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 212 Error 108 error C2275: 'HDC' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 231 Error 60 error C2275: 'Gdiplus::MetafileHeader' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2224 Error 67 error C2275: 'Gdiplus::GpMetafile' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Error 31 error C2275: 'Gdiplus::GpImage' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Error 37 error C2275: 'Gdiplus::GpImage' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Error 48 error C2275: 'Gdiplus::GpBitmap' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Error 54 error C2275: 'Gdiplus::GpBitmap' : illegal use of this type as an expression c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Error 3 error C2146: syntax error : missing ';' before identifier 'IImageBytes' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 74 Error 6 error C2146: syntax error : missing ';' before identifier 'id' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 280 Error 73 error C2146: syntax error : missing ')' before identifier 'referenceHdc' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2310 Error 81 error C2146: syntax error : missing ')' before identifier 'referenceHdc' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2321 Error 93 error C2146: syntax error : missing ')' before identifier 'referenceHdc' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 195 Error 101 error C2146: syntax error : missing ')' before identifier 'referenceHdc' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 212 Error 109 error C2146: syntax error : missing ')' before identifier 'referenceHdc' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 231 Error 96 error C2143: syntax error : missing ';' before '{' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 199 Error 104 error C2143: syntax error : missing ';' before '{' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 218 Error 33 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Error 39 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Error 50 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Error 56 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Error 62 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2224 Error 69 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Error 75 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2310 Error 83 error C2078: too many initializers c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2321 Error 29 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Error 35 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Error 46 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Error 52 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Error 58 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2222 Error 65 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Error 71 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2309 Error 79 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2320 Error 88 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 75 Error 91 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 194 Error 99 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 211 Error 107 error C2065: 'stream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 230 Error 66 error C2065: 'metafile' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Error 28 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Error 34 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Error 45 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Error 51 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Error 57 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2222 Error 64 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2262 Error 70 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2309 Error 78 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2320 Error 87 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 75 Error 90 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 194 Error 98 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 211 Error 106 error C2065: 'IStream' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 230 Error 30 error C2065: 'image' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1133 Error 36 error C2065: 'image' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1139 Error 59 error C2065: 'header' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2224 Error 47 error C2065: 'bitmap' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1286 Error 53 error C2065: 'bitmap' : undeclared identifier c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1292 Error 12 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 443 Error 13 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 444 Error 14 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 445 Error 15 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 453 Error 41 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1244 Error 42 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1247 Error 43 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1250 Error 44 error C2061: syntax error : identifier 'PROPID' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1262 Error 9 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 384 Error 10 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 395 Error 11 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 405 Error 17 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 505 Error 18 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 516 Error 19 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 758 Error 20 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 813 Error 22 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 820 Error 24 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 829 Error 26 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusheaders.h 855 Error 40 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 1156 Error 63 error C2061: syntax error : identifier 'IStream' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2242 Error 86 error C2061: syntax error : identifier 'byte' c:\program files\microsoft sdks\windows\v7.0\include\gdipluspath.h 133 Error 5 error C2059: syntax error : 'public' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusimaging.h 74 Error 77 error C2059: syntax error : ')' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2316 Error 85 error C2059: syntax error : ')' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusflat.h 2327 Error 95 error C2059: syntax error : ')' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 198 Error 103 error C2059: syntax error : ')' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 217 Error 111 error C2059: syntax error : ')' c:\program files\microsoft sdks\windows\v7.0\include\gdiplusmetafile.h 236 I tried updating my sdk to 7.0 but it did not help. I'm not even making any calls to the API. Thanks

    Read the article

  • OutOfMemoryException with Image.Clone - Only on Windows 2003

    - by Jeff Rapp
    So here's my issue. I have an image that I need to shrink. The original image is a grayscale PNG, which isn't a huge issues except that when I shrink it down, the thermal label printers pickup the artifacts and print them on the label. So, what I did was change the image to black & white (Format1bppIndexed) before resizing, like this: Dim bte() As Byte = System.Convert.FromBase64String(imgStr) Dim ms As New IO.MemoryStream(bte) Dim bmp As New System.Drawing.Bitmap(ms) Dim monoImage As Drawing.Bitmap = New Drawing.Bitmap(1200, 1800, Drawing.Imaging.PixelFormat.Format1bppIndexed) Dim rect As New Drawing.Rectangle(0, 0, 1200, 1800) monoImage = bmp.Clone(rect, Drawing.Imaging.PixelFormat.Format1bppIndexed) And then I resize it. This code works fine on my Windows 7 machine, but when I run it on the Windows 2003 Server box that it calls home, it always throws an OutOfMemoryException when it hits the bmp.Clone line. Any ideas as to what's happening, or perhaps a better solution to converting the image to B&W?

    Read the article

  • JPEG artifacts removal in C#

    - by Arcturus
    Hi all I am building a website for a club that is part of a mother organisation. I am downloading (leeching ;) ) the images that where put on profile pages of the mother organisation to show on my own page. But their website has a nice white background, and my website has a nice gray gradient on the background. This does not match nicely. So my idea was to edit the images before saving them to my server. I am using GDI+ to enhance my images, and when I use the method MakeTransparent of Bitmap, it does work, and it does do what its supposed to do, but I still have these white jpeg artifacts all over the place. The artifacts makes the image so bad, I am better off not making the image transparent and just leaving it white, but thats really ugly on my own website. I can always at a nice border with a white background of course, but I rather change the background to transparent. So I was wondering if and how I can remove some simple JPEG artifacts in C#. Has anyone ever done this before? Thanks for your time. Example image: Transformed image:

    Read the article

  • Creating a GraphicsPath from a semi-transparent bitmap

    - by Moozhe
    I want to create a GraphicsPath and a list of Points to form the outline of the non-transparent area of a bitmap. If needed, I can guarantee that each image has only one solid collection of nontransparent pixels. So for example, I should be able to record the points either clockwise or counter-clockwise along the edge of the pixels and perform a full closed loop. The speed of this algorithm is not important. However, the efficiency of the resulting points is semi-important if I can skip some points to reduce in a smaller and less complex GraphicsPath. I will list my current code below which works perfectly with most images. However, some images which are more complex end up with paths which seem to connect in the wrong order. I think I know why this occurs, but I can't come up with a solution. public static Point[] GetOutlinePoints(Bitmap image) { List<Point> outlinePoints = new List<Point>(); BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte[] originalBytes = new byte[image.Width * image.Height * 4]; Marshal.Copy(bitmapData.Scan0, originalBytes, 0, originalBytes.Length); for (int x = 0; x < bitmapData.Width; x++) { for (int y = 0; y < bitmapData.Height; y++) { byte alpha = originalBytes[y * bitmapData.Stride + 4 * x + 3]; if (alpha != 0) { Point p = new Point(x, y); if (!ContainsPoint(outlinePoints, p)) outlinePoints.Add(p); break; } } } for (int y = 0; y < bitmapData.Height; y++) { for (int x = bitmapData.Width - 1; x >= 0; x--) { byte alpha = originalBytes[y * bitmapData.Stride + 4 * x + 3]; if (alpha != 0) { Point p = new Point(x, y); if (!ContainsPoint(outlinePoints, p)) outlinePoints.Add(p); break; } } } for (int x = bitmapData.Width - 1; x >= 0; x--) { for (int y = bitmapData.Height - 1; y >= 0; y--) { byte alpha = originalBytes[y * bitmapData.Stride + 4 * x + 3]; if (alpha != 0) { Point p = new Point(x, y); if (!ContainsPoint(outlinePoints, p)) outlinePoints.Add(p); break; } } } for (int y = bitmapData.Height - 1; y >= 0; y--) { for (int x = 0; x < bitmapData.Width; x++) { byte alpha = originalBytes[y * bitmapData.Stride + 4 * x + 3]; if (alpha != 0) { Point p = new Point(x, y); if (!ContainsPoint(outlinePoints, p)) outlinePoints.Add(p); break; } } } // Added to close the loop outlinePoints.Add(outlinePoints[0]); image.UnlockBits(bitmapData); return outlinePoints.ToArray(); } public static bool ContainsPoint(IEnumerable<Point> points, Point value) { foreach (Point p in points) { if (p == value) return true; } return false; } And when I turn the points into a path: GraphicsPath outlinePath = new GraphicsPath(); outlinePath.AddLines(_outlinePoints); Here's an example showing what I want. The red outline should be an array of points which can be made into a GraphicsPath in order to perform hit detection, draw an outline pen, and fill it with a brush.

    Read the article

  • Winforms fixed single border on custom shaped control

    - by JD
    Hi all, I have created a custom control inheriting from a panel in .NET 3.5 The panel has a custom polygon border, which comes from a pointF array (In diagram, control is highlighted yellow). Fig 1 shows the control with BorderStyle none. Fig 2 with BorderStyle fixed-single As shown in Fig 2, the border follows the Rectangle bounding the control. IS there a way to make the border follow the actual border of the control set by the polygon? FYI the polygon is created using a GraphicsPath object. Drawing the line with GDI+ does not work, as the control clips the line and it looks awful... Fig1 Fig2

    Read the article

  • Using Bitmap.LockBits and Marshal.Copy in IronPython not changing image as expected

    - by Leonard H Martin
    Hi all, I have written the following IronPython code: import clr clr.AddReference("System.Drawing") from System import * from System.Drawing import * from System.Drawing.Imaging import * originalImage = Bitmap("Test.bmp") def RedTint(bitmap): bmData = bitmap.LockBits(Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb) ptr = bmData.Scan0 bytes = bmData.Stride * bitmap.Height rgbValues = Array.CreateInstance(Byte, bytes) Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes) for i in rgbValues[::3]: i = 255 Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes) bitmap.UnlockBits(bmData) return bitmap newPic = RedTint(originalImage) newPic.Save("New.bmp") Which is my interpretation of this MSDN code sample: http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx except that I am saving the altered bitmap instead of displaying it in a Form. The code runs, however the newly saved bitmap is an exact copy of the original image with no sign of any changes having occurred (it's supposed to create a red tint). Could anyone advise what's wrong with my code? The image I'm using is simply a 24bpp bitmap I created in Paint (it's just a big white rectangle!), using IronPython 2.6 and on Windows 7 (x64) with .Net Framework 3.5 SP1 installed.

    Read the article

  • deleting HBITMAP causes an access violation at runtime.

    - by Oliver
    Hi, I have the following code to take a screenshot of a window, and get the colour of a specific pixel in it: void ProcessScreenshot(HWND hwnd){ HDC WinDC; HDC CopyDC; HBITMAP hBitmap; RECT rt; GetClientRect (hwnd, &rt); WinDC = GetDC (hwnd); CopyDC = CreateCompatibleDC (WinDC); //Create a bitmap compatible with the DC hBitmap = CreateCompatibleBitmap (WinDC, rt.right - rt.left, //width rt.bottom - rt.top);//height SelectObject (CopyDC, hBitmap); BitBlt (CopyDC, //destination 0,0, rt.right - rt.left, //width rt.bottom - rt.top, //height WinDC, //source 0, 0, SRCCOPY); COLORREF col = ::GetPixel(CopyDC,145,293); // Do some stuff with the pixel colour.... delete hBitmap; ReleaseDC(hwnd, WinDC); ReleaseDC(hwnd, CopyDC); } the line 'delete hBitmap;' causes a runtime error: an access violation. I guess I can't just delete it like that? Because bitmaps take up a lot of space, if I don't get rid of it I will end up with a huge memory leak. My question is: Does releasing the DC the HBITMAP is from deal with this, or does it stick around even after I have released the DC? If the later is the case, how do I correctly get rid of the HBITMAP?

    Read the article

  • Editing 8bpp indexed Bitmaps

    - by Pedro Sá
    hi, i'm trying to edit the pixels of a 8bpp. Since this PixelFormat is indexed i'm aware that it uses a Color Table to map the pixel values. Even though I can edit the bitmap by converting it to 24bpp, 8bpp editing is much faster (13ms vs 3ms). But, changing each value when accessing the 8bpp bitmap results in some random rgb colors even though the PixelFormat remains 8bpp. I'm currently developing in c# and the algorithm is as follows: (C#) 1- Load original Bitmap at 8bpp 2- Create Empty temp Bitmap with 8bpp with the same size as the original 3-LockBits of both bitmaps and, using P/Invoke, calling c++ method where I pass the Scan0 of each BitmapData object. (I used a c++ method as it offers better performance when iterating through the Bitmap's pixels) (C++) 4- Create a int[256] palette according to some parameters and edit the temp bitmap bytes by passing the original's pixel values through the palette. (C#) 5- UnlockBits. My question is how can I edit the pixel values without having the strange rgb colors, or even better, edit the 8bpp bitmap's Color Table? Regards, Pedro

    Read the article

  • C# winforms: graphics.DrawImage problem

    - by Tony
    Hi, I have a really strange problem with Graphics.DrawImage method. I have the PictureBox control in the Panel control with AllowScroll property = true. The program cuts the image on small parts basing on the area selected by the user. I load the image 300x547 and select the area (the red rectangle): program properly cuts the image: then, I load another image 427x640: and then, as the result I see that the image is not cut properly. Each img.jpg file has properly width & height but the drawn image is too small: here's the code snippet - it saves the bitmap area selected by the user: Bitmap bmp = new Bitmap(selectedAreaRECT.Width, selectedAreaRECT.Height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(OriginalIMG, 0,0, selectedAreaRECT, GraphicsUnit.Pixel); g.Save(); g.Dispose(); bmp.Save(AppDomain.CurrentDomain.BaseDirectory + @"\Temp\" + "img1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); As You see, the code is the same for the img1.jpg from image A and from Image B. I'm trying to resolve that stupid problem for too long, I don't know what's the reason of that problem. I tried diffrent constructors of the DrawImage method, with no success

    Read the article

  • Deserializing Metafile

    - by Kildareflare
    I have an application that works with Enhanced Metafiles. I am able to create them, save them to disk as .emf and load them again no problem. I do this by using the gdi32.dll methods and the DLLImport attribute. However, to enable Version Tolerant Serialization I want to save the metafile in an object along with other data. This essentially means that I need to serialize the metafile data as a byte array and then deserialize it again in order to reconstruct the metafile. The problem I have is that the deserialized data would appear to be corrupted in some way, since the method that I use to reconstruct the Metafile raises a "Parameter not valid exception". At the very least the pixel format and resolutions have changed. Code use is below. [DllImport("gdi32.dll")] public static extern uint GetEnhMetaFileBits(IntPtr hemf, uint cbBuffer, byte[] lpbBuffer); [DllImport("gdi32.dll")] public static extern IntPtr SetEnhMetaFileBits(uint cbBuffer, byte[] lpBuffer); [DllImport("gdi32.dll")] public static extern bool DeleteEnhMetaFile(IntPtr hemf); The application creates a metafile image and passes it to the method below. private byte[] ConvertMetaFileToByteArray(Image image) { byte[] dataArray = null; Metafile mf = (Metafile)image; IntPtr enhMetafileHandle = mf.GetHenhmetafile(); uint bufferSize = GetEnhMetaFileBits(enhMetafileHandle, 0, null); if (enhMetafileHandle != IntPtr.Zero) { dataArray = new byte[bufferSize]; GetEnhMetaFileBits(enhMetafileHandle, bufferSize, dataArray); } DeleteEnhMetaFile(enhMetafileHandle); return dataArray; } At this point the dataArray is inserted into an object and serialized using a BinaryFormatter. The saved file is then deserialized again using a BinaryFormatter and the dataArray retrieved from the object. The dataArray is then used to reconstruct the original Metafile using the following method. public static Image ConvertByteArrayToMetafile(byte[] data) { Metafile mf = null; try { IntPtr hemf = SetEnhMetaFileBits((uint)data.Length, data); mf = new Metafile(hemf, true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } return (Image)mf; } The reconstructed metafile is then saved saved to disk as a .emf (Model) at which point it can be accessed by the Presenter for display. private static void SaveFile(Image image, String filepath) { try { byte[] buffer = ConvertMetafileToByteArray(image); File.WriteAllBytes(filepath, buffer); //will overwrite file if it exists } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } The problem is that the save to disk fails. If this same method is used to save the original Metafile before it is serialized everything is OK. So something is happening to the data during serialization/deserializtion. Indeed if I check the Metafile properties in the debugger I can see that the ImageFlags, PropertyID, resolution and pixelformats change. Original Format32bppRgb changes to Format32bppArgb Original Resolution 81 changes to 96 I've trawled though google and SO and this has helped me get this far but Im now stuck. Does any one have enough experience with Metafiles / serialization to help..? EDIT: If I serialize/deserialize the byte array directly (without embedding in another object) I get the same problem.

    Read the article

  • Detecting ClearType-optimized fonts

    - by Josh Kelley
    Question: Is there a way to check if a given font is one of Microsoft's ClearType-optimized fonts? I guess I could simply hard-code the list of font names, since it's a relatively short list, but that seems a bit ugly. Would the font names be the same regardless of Windows' locale and language settings? Background: PuTTY looks really ugly with bold, ClearType-enabled, Consolas text. I decided to play around with the source and see if I could figure out the problem, and I think I tracked it down to the following (abbreviated) code: font_height = cfg.font.height; if (font_height > 0) { font_height = -MulDiv(font_height, GetDeviceCaps(hdc, LOGPIXELSY), 72); } } font_width = 0; #define f(i,c,w,u) \ fonts[i] = CreateFont (font_height, font_width, 0, 0, w, FALSE, u, FALSE, \ c, OUT_DEFAULT_PRECIS, \ CLIP_DEFAULT_PRECIS, FONT_QUALITY(cfg.font_quality), \ FIXED_PITCH | FF_DONTCARE, cfg.font.name) f(FONT_NORMAL, cfg.font.charset, fw_dontcare, FALSE); SelectObject(hdc, fonts[FONT_NORMAL]); GetTextMetrics(hdc, &tm); font_height = tm.tmHeight; font_width = tm.tmAveCharWidth; f(FONT_BOLD, cfg.font.charset, fw_bold, FALSE); The intent is to pick a bold font that fits the same dimensions as the normal font. I'm assuming that PuTTY's Consolas text looks ugly because, since Consolas is so heavily optimized to be layed out on specific pixel boundaries, trying to shoehorn it into arbitrary dimensions produces bad results. So it seems like an appropriate fix would be to detect ClearType-optimized fonts and try and create the bold versions of those fonts using the same width and height as the initial CreateFont call.

    Read the article

  • Gradient fill bitmap and CreatePatternBrush just gives black fill instead of gradient

    - by mtopley
    I'm trying to create a Gradient Brush in windows mobile as follows: HBITMAP hBitmap = CreateBitmap(16, 16, 1, 16, NULL); HDC hDC = CreateCompatibleDC(NULL); HBITMAP hPrevious = SelectObject(hDC,hBitmap); TRIVERTEX vert[2]; GRADIENT_RECT gRect; ... fill in vert and gRect GradientFill(hDC, vert, 2,&gRect, 1, Direction); SelectObject(hDC, hPrevious); Delete(hDC); HBRUSH hPatternBrush = CreatePatternBrush(hBitmap); HDC hDC = BeginPaint(hWnd, &ps); SelectObject(hDC, hPatternBrush); RoundRect(hDC, ...); EndPaint(hWND, &ps); This code create a round rect with a black background, not the pattern brush. I can draw the hBitmap which is used to create the brush and it draws the gradient. Anyone got a solution?

    Read the article

  • BitBlt code not working

    - by MusiGenesis
    I'm trying to use this code to draw a Bitmap directly onto a PictureBox: Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp"); Graphics grDest = Graphics.FromHwnd(pictureBox1.Handle); Graphics grSrc = Graphics.FromImage(bmp); IntPtr hdcDest = grDest.GetHdc(); IntPtr hdcSrc = grSrc.GetHdc(); BitBlt(hdcDest, 0, 0, pictureBox1.Width, pictureBox1.Height, hdcSrc, 0, 0, (uint)TernaryRasterOperations.SRCCOPY); // 0x00CC0020 grDest.ReleaseHdc(hdcDest); grSrc.ReleaseHdc(hdcSrc); but instead of rendering the Bitmap's contents it just draws a solid block of nearly-black. I'm pretty sure the problem is with the source hDC, because if I change SRCCOPY to WHITENESS in the above code, it draws a solid white block, as expected. Note: this next snippet works fine, so there's nothing wrong with the bitmap itself: Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp"); pictureBox1.Image = bmp;

    Read the article

  • Ellipse Drawing WPF Animation

    - by widmayer
    I am developing a control that is a rectangle area and will draw an ellipse in the rectangle area when a trigger occurs. This control will be able to host other controls like, textbox's, buttons, etc. so the circle will be drawn around them when triggered. I want the circle being drawn as an animation like you were circling the inner controls with a pen. My question is whats the best way to accomplish this. I've been doing some research and I could use WPF animation or I could use GDI+ to accomplish the tasks. I am new to WPF animation so that is why I am asking the question.

    Read the article

  • A generic error in GDI+ with ToolStrip in ManagerRenderMode

    - by volody
    I have a vb.net form with ToolStrip menu RenderMode - ManagerRenderMode LayoutStyle - HorizontalStackWithOverflow My development environment is .net 4.0, VS2010, windows 7 x64; but occasionally I am getting next error A generic error occurred in GDI+. Stacktrace: at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height) at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect) at System.Windows.Forms.ToolStripProfessionalRenderer.FillWithDoubleGradient(Color beginColor, Color middleColor, Color endColor, Graphics g, Rectangle bounds, Int32 firstGradientWidth, Int32 secondGradientWidth, LinearGradientMode mode, Boolean flipHorizontal) at System.Windows.Forms.ToolStripProfessionalRenderer.RenderToolStripBackgroundInternal(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStripProfessionalRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStripRenderer.DrawToolStripBackground(ToolStripRenderEventArgs e) at System.Windows.Forms.ToolStrip.OnPaintBackground(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    Read the article

  • Stable random color algorithm

    - by Olmo
    Here we have an interesting real-world algorithm requirement involving colors. 1) Nice random colors: In ordeeing to draw a beautifull chart (i.e: pie chart) we need to pick a random set of Colors that: a) are different enought b) Play nicely Doesnt Look hard. For example u fix bright and saturation and divide hue in steps of 360/Num_sectors 2) Stable: given Pie1 with sectors with labes ('A','B','C') and Pie2 with sector with labels ('B','C','D'), will be nice if color('B',pie1)= color('B',pie2) and the same for 'C' and so on, so people don't get crazy when seeing similar updated charts, even if some sectors appear some dissapeared or the number of sectors changed. The label is the only stable thing. 3) hard-coded colors: the algorithm allows hardcoded label-color relationships as an input but stills doing a good work (1 & 2) for the rest of free labels. I think this algorithm, even if it looks quite ad-hoc, will be usefull in more then one situation. Any ideas?

    Read the article

  • What file format can represent an uncompressed raster image at 48 or 64 bits per pixel?

    - by finnw
    I am creating screenshots under Windows and using the LockBits function from GDI+ to extract the pixel data, which will then be written to a file. To maximise performance I am also: Using the same PixelFormat as the source bitmap, to avoid format conversion Using the ImageLockModeUserInputBuf flag to extract the pixel data into a pre-allocated buffer This pre-allocated buffer (pointed to by BitmapData::Scan0) is part of a memory-mapped file (to avoid copying the pixel data again.) I will also be writing the code that reads the file, so I can use (or invent) any format I wish. However I would prefer to use a well-known format that existing programs (ideally web browsers) are able to read, because that means I can visually confirm that the images are correct before writing the code for the other program (that reads the image.) I have implemented this successfully for the PixelFormat32bppRGB format, which matches the format of a 32bpp BMP file, so if I extract the pixel data directly into the memory-mapped BMP file and prefix it with a BMP header I get a valid BMP image file that can be opened in Paint and most browsers. Unfortunately one of the machines I am testing on returns pixels in PixelFormat64bppPARGB format (presumably this is influenced by the video adapter driver) and there is no corresponding BMP pixel format for this. Converting to a 16, 24 or 32bpp BMP format slows the program down considerably (as well as being lossy) so I am looking for a file format that can use this pixel format without conversion, so I can extract directly into the memory-mapped file as I have done with the 32bpp format. What raster image file formats support 48bpp and/or 64bpp?

    Read the article

  • Convert Pen to IntPtr

    - by Bevin
    Is there a simple way to convert a System.Drawing.Pen into its unmanaged counterpart? Like, if you had a Pen like this: Pen p = new Pen(Color.Blue, 1f); IntPtr ptr = p.ToPtr(); I know this code doesn't work, but is there a way to do it similarly?

    Read the article

  • Drawing a TextBox in an extended Glass Frame w/o WPF

    - by Lazlo
    I am trying to draw a TextBox on the extended glass frame of my form. I won't describe this technique, it's well-known. Here's an example for those who haven't heard of it: http://www.danielmoth.com/Blog/Vista-Glass-In-C.aspx The thing is, it is complex to draw over this glass frame. Since black is considered to be the 0-alpha color, anything black disappears. There are apparently ways of countering this problem: drawing complex GDI+ shapes are not affected by this alpha-ness. For example, this code can be used to draw a Label on glass (note: GraphicsPath is used instead of DrawString in order to get around the horrible ClearType problem): public class GlassLabel : Control { public GlassLabel() { this.BackColor = Color.Black; } protected override void OnPaint(PaintEventArgs e) { GraphicsPath font = new GraphicsPath(); font.AddString( this.Text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size, Point.Empty, StringFormat.GenericDefault); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.FillPath(new SolidBrush(this.ForeColor), font); } } Similarly, such an approach can be used to create a container on the glass area. Note the use of the polygons instead of the rectangle - when using the rectangle, its black parts are considered as alpha. public class GlassPanel : Panel { public GlassPanel() { this.BackColor = Color.Black; } protected override void OnPaint(PaintEventArgs e) { Point[] area = new Point[] { new Point(0, 1), new Point(1, 0), new Point(this.Width - 2, 0), new Point(this.Width - 1, 1), new Point(this.Width -1, this.Height - 2), new Point(this.Width -2, this.Height-1), new Point(1, this.Height -1), new Point(0, this.Height - 2) }; Point[] inArea = new Point[] { new Point(1, 1), new Point(this.Width - 1, 1), new Point(this.Width - 1, this.Height - 1), new Point(this.Width - 1, this.Height - 1), new Point(1, this.Height - 1) }; e.Graphics.FillPolygon(new SolidBrush(Color.FromArgb(240, 240, 240)), inArea); e.Graphics.DrawPolygon(new Pen(Color.FromArgb(55, 0, 0, 0)), area); base.OnPaint(e); } } Now my problem is: How can I draw a TextBox? After lots of Googling, I came up with the following solutions: Subclassing the TextBox's OnPaint method. This is possible, although I could not get it to work properly. It should involve painting some magic things I don't know how to do yet. Making my own custom TextBox, perhaps on a TextBoxBase. If anyone has good, valid and working examples, and thinks this could be a good overall solution, please tell me. Using BufferedPaintSetAlpha. (http://msdn.microsoft.com/en-us/library/ms649805.aspx). The downsides of this method may be that the corners of the textbox might look odd, but I can live with that. If anyone knows how to implement that method properly from a Graphics object, please tell me. I personally don't, but this seems the best solution so far. To be honest, I found a great C++ article, but I am way too lazy to convert it. http://weblogs.asp.net/kennykerr/archive/2007/01/23/controls-and-the-desktop-window-manager.aspx Note: If I ever succeed with the BufferedPaint methods, I swear to s/o that I will make a simple DLL with all the common Windows Forms controls drawable on glass.

    Read the article

  • Does MS Access 2010 have Tif image control display issue?

    - by ChuckB
    We run MS Access as the front end for most of our business. When we upgraded from Access 2000 to Access 2003 the image control we used to print out Tif images failed to load Tifs anymore. A bit of Googling showed that MS did this intentionally and I'm wondering if the problem still happens in Access 2010. Can someone with a downloaded copy drop an image control on an Access 2010 form or report and try to get it to display a Tif file?

    Read the article

  • Use native HBitmap in C# while preserving alpha channel/transparency. Please check this code, it works on my computer...

    - by David
    Let's say I get a HBITMAP object/handle from a native Windows function. I can convert it to a managed bitmap using Bitmap.FromHbitmap(nativeHBitmap), but if the native image has transparency information (alpha channel), it is lost by this conversion. There are a few questions on Stack Overflow regarding this issue. Using information from the first answer of this question (How to draw ARGB bitmap using GDI+?), I wrote a piece of code that I've tried and it works. It basically gets the native HBitmap width, height and the pointer to the location of the pixel data using GetObject and the BITMAP structure, and then calls the managed Bitmap constructor: Bitmap managedBitmap = new Bitmap(bitmapStruct.bmWidth, bitmapStruct.bmHeight, bitmapStruct.bmWidth * 4, PixelFormat.Format32bppArgb, bitmapStruct.bmBits); As I understand (please correct me if I'm wrong), this does not copy the actual pixel data from the native HBitmap to the managed bitmap, it simply points the managed bitmap to the pixel data from the native HBitmap. And I don't draw the bitmap here on another Graphics (DC) or on another bitmap, to avoid unnecessary memory copying, especially for large bitmaps. I can simply assign this bitmap to a PictureBox control or the the Form BackgroundImage property. And it works, the bitmap is displayed correctly, using transparency. When I no longer use the bitmap, I make sure the BackgroundImage property is no longer pointing to the bitmap, and I dispose both the managed bitmap and the native HBitmap. The Question: Can you tell me if this reasoning and code seems correct. I hope I will not get some unexpected behaviors or errors. And I hope I'm freeing all the memory and objects correctly. private void Example() { IntPtr nativeHBitmap = IntPtr.Zero; /* Get the native HBitmap object from a Windows function here */ // Create the BITMAP structure and get info from our nativeHBitmap NativeMethods.BITMAP bitmapStruct = new NativeMethods.BITMAP(); NativeMethods.GetObjectBitmap(nativeHBitmap, Marshal.SizeOf(bitmapStruct), ref bitmapStruct); // Create the managed bitmap using the pointer to the pixel data of the native HBitmap Bitmap managedBitmap = new Bitmap( bitmapStruct.bmWidth, bitmapStruct.bmHeight, bitmapStruct.bmWidth * 4, PixelFormat.Format32bppArgb, bitmapStruct.bmBits); // Show the bitmap this.BackgroundImage = managedBitmap; /* Run the program, use the image */ MessageBox.Show("running..."); // When the image is no longer needed, dispose both the managed Bitmap object and the native HBitmap this.BackgroundImage = null; managedBitmap.Dispose(); NativeMethods.DeleteObject(nativeHBitmap); } internal static class NativeMethods { [StructLayout(LayoutKind.Sequential)] public struct BITMAP { public int bmType; public int bmWidth; public int bmHeight; public int bmWidthBytes; public ushort bmPlanes; public ushort bmBitsPixel; public IntPtr bmBits; } [DllImport("gdi32", CharSet = CharSet.Auto, EntryPoint = "GetObject")] public static extern int GetObjectBitmap(IntPtr hObject, int nCount, ref BITMAP lpObject); [DllImport("gdi32.dll")] internal static extern bool DeleteObject(IntPtr hObject); }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >