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
  1. Home
  2. General Programming
  3. C#
  4. GDI GradientFill

GDI GradientFill

Scheduled Pinned Locked Moved C#
csharpgraphicshelpquestion
3 Posts 2 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.
  • M Offline
    M Offline
    Mathew Hall
    wrote on last edited by
    #1

    I'm experimenting with using GDI from C# and I'm not having much luck with the GradientFill function. Anyone managed to get this working? (Google/pinvoke.net are not much help :sigh: ) "I think I speak on behalf of everyone here when I say huh?" - Buffy

    C 1 Reply Last reply
    0
    • M Mathew Hall

      I'm experimenting with using GDI from C# and I'm not having much luck with the GradientFill function. Anyone managed to get this working? (Google/pinvoke.net are not much help :sigh: ) "I think I speak on behalf of everyone here when I say huh?" - Buffy

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why ? Do you mean you can't call it, or it does nothing ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      M 1 Reply Last reply
      0
      • C Christian Graus

        Why ? Do you mean you can't call it, or it does nothing ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

        M Offline
        M Offline
        Mathew Hall
        wrote on last edited by
        #3

        why? why not? :) (For my article XPExplorerBar[^] I'm doing animation with transparency which can be quite slow using GDI+. Thought I might try the same thing with GDI since it is hardware accelerated to see if I can get a decent performance boost) Do you mean you can't call it, or it does nothing? It doesn't do anything, yet GradientFill returns that it was successful. This is what I have so far: [DllImport("Msimg32.dll", CharSet=CharSet.Auto, SetLastError=true)] public static extern bool GradientFill(IntPtr hdc, TRIVERTEX[] pVertex, int dwNumVertex, ref GRADIENT_RECT pMesh, int dwNumMesh, int dwMode); [StructLayout(LayoutKind.Sequential)] public struct TRIVERTEX { public long x; public long y; public ushort Red; public ushort Green; public ushort Blue; public ushort Alpha; } [StructLayout(LayoutKind.Sequential)] public struct GRADIENT_RECT { public ulong UpperLeft; public ulong LowerRight; } public bool FillRectangle(IntPtr hdc, Color startColor, Color endColor, int x, int y, int width, int height) { TRIVERTEX[] vert = new TRIVERTEX[2]; GRADIENT_RECT rect = new GRADIENT_RECT(); vert[0].x = x; vert[0].y = y; vert[0].Red = (ushort) (startColor.R << 8); vert[0].Green = (ushort) (startColor.G << 8); vert[0].Blue = (ushort) (startColor.B << 8); vert[0].Alpha = 0; vert[1].x = x + width; vert[1].y = y + height; vert[1].Red = (ushort) (endColor.R << 8); vert[1].Green = (ushort) (endColor.G << 8); vert[1].Blue = (ushort) (endColor.B << 8); vert[1].Alpha = 0; rect.UpperLeft = 0; rect.LowerRight = 1; return GradientFill(hdc, vert, 2, ref rect, 1, 0); } "I think I speak on behalf of everyone here when I say huh?" - Buffy

        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