Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Alpha Transparence problems with Image Class

Alpha Transparence problems with Image Class

Scheduled Pinned Locked Moved C#
graphicsjsonhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kir Birger
    wrote on last edited by
    #1

    I've been battling this for a long time, and i managed to get it working with the Icon class, but due to recent changes in a program I'm working on, I now have to keep all my icons as Image class members. This gives me the black border around alpha transparent pixels in my icons. This is the code i'm using: For the API: private static uint SHGFI_ICON = 0x100; // get icon private static uint SHGFI_LARGEICON = 0x0; // get large icon private static uint SHGFI_SMALLICON = 0x1; // get small icon [DllImport("Shell32.dll")] private static extern int SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, int cbfileInfo, uint uFlags); private struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public int dwAttributes; public string szDisplayName; public string szTypeName; } public enum FileIconSize { Small, // 16x16 pixels Large // 32x32 pixels } public static Image GetFileIcon(string fullpath, FileIconSize size) { SHFILEINFO info = new SHFILEINFO(); uint flags = SHGFI_ICON; //uint flags = SHGFI_ICON|SHGFI_SYSICONINDEX; if (size == FileIconSize.Small) { flags |= SHGFI_SMALLICON; } int retval = SHGetFileInfo(fullpath, 0, ref info, System.Runtime.InteropServices.Marshal.SizeOf(info), flags); if (retval == 0) { return null; // error occured } System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(info.hIcon); System.Windows.Forms.ImageList imgList = new ImageList(); imgList.ColorDepth = ColorDepth.Depth32Bit; imgList.ImageSize = icon.Size; imgList.Images.Add(icon); return imgList.Images[0]; } Actual working code on a Windows Form: Graphics g = Graphics.FromHwnd(this.Handle); g.FillRectangle(System.Drawing.SystemBrushes.ControlDark,20,50,32,32); Image ico; ico = API.GetIcon(ofd1.FileName, API.FileIconSize.Small); g.DrawImage(ico, 20,50); can anyone tell me what i'm doing wrong? i thought i had taken care of all the little possible ways to screw it up, such as converting it to a bitmap...

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups