Re: How to get an associated file icon without the Alpha Channel i

From: Mike D Sutton (EDais_at_mvps.org)
Date: 09/04/04


Date: Sat, 4 Sep 2004 11:34:31 +0100


> This is what I've done so far.
<code snipped>

First up don't store the icon handle in a static variable; this is asking for trouble since you assume (presumably) that the
function is called with bad parameters at the end of the application to clean up the last icon handle. As far as I can see there's
no reason for keeping it around after the end of the routine anyway, just make the OLE picture object own the handle and there's no
problems.
When you call SHGetFileInfo() you needn't include the SHGFI_USEFILEATTRIBUTES as far as I can see.
You don't need to select the colour bitmap into the temporary DC, GetDIBits() just requires a device context handle rather than
requiring the DC that contains the Bitmap (Indeed the documentation actually specifies that the Bitmap _shouldn't_ be selected into
this DC, however I think this only applies for some flavours of DDB.)
Rather than filling out the header structure yourself, you can use GetDIBits() to do this for you - have a look at chapter 3 of the
DDB article on my site for examples of this. Also the alpha thresholding example I gave you in my previous post which you've
integrated into your routine was operating on a DWord array where as you're working on a byte array which of course will never have
the high byte set (a byte only has a low byte!) As a by-product of this, because you've only allocated an array of bytes it's
actually only quarter of the required size and so GetDIBits() overwrites the end of the buffer causing you all kinds of problems!
When you're editing the mask data, you're attempting to operate on it in the same way as the colour data by getting GetDIBits() to
perform the bit-depth conversion for you into 32-bit however GDI will convert both colours to an alpha value of 0 (default) and as
such the routine as it stands will do nothing. Instead, either extract the data in it's native format and work on it from there or
select the mask Bitmap into your temporary DC and just use SetPixelV() to draw the new mask data.
Finally, make sure you're de-selecting your Bitmaps and destroying the temporary DC handle before the end of the routine since
currently you've got some GDI leaks in there.
Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: http://www.mvps.org/EDais/



Relevant Pages

  • Re: Delphi Roadmap (by David I)
    ... The programloads a bitmap, and applies a gaussian blur to it. ... image was 4105x3182 pixels. ... Under win32, my gaussian blur routine uses 3.0-3.1 seconds per run, ... Without copying to and from this buffer, ...
    (borland.public.delphi.non-technical)
  • Re: Nobody likes BASICdraw
    ... It has received the worst ratings of any recent graphics program on ... Not a single person has posted a routine for it. ... bitmap (arbitrary shapes, or operations using a masking bitmap ... Nowadays, images can be huge. ...
    (comp.programming)
  • Re: analysing a bitmap
    ... >i'm trying to copy all closed pixels of the same color of a bitmap (only ... Now the fill routine... ... the stack limit. ... dumping coordinates to a memo1 box so you can see where it's going, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Trying to write text to bitmap
    ... You're using DIB section, GetDIBits only handle DDB. ... But the good news is that you do not even need to call GetDIBits. ... rememeber to clear the bitmap ... > GdiFlush(); ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Screen-Shot
    ... How can I save to bitmap the image present in my hdc? ... The GetDIBits it isn't present in Windows CE! ... Rather than the GetDIBits function you mention above you can use ...
    (microsoft.public.windowsce.embedded)