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. Gradient Texture with Transparency

Gradient Texture with Transparency

Scheduled Pinned Locked Moved C#
graphicstutorialquestionlearning
4 Posts 2 Posters 7 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.
  • B Offline
    B Offline
    BoneSoft
    wrote on last edited by
    #1

    Does anybody have an idea how to draw an image (like using TextureBrush) with gradient transparency (like using LinearGradientBrush)? The only examples I can find on drawing an image with transparency use ColorMatrix to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is a LinearGradientTextureBrush, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions.

    "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

    B M 2 Replies Last reply
    0
    • B BoneSoft

      Does anybody have an idea how to draw an image (like using TextureBrush) with gradient transparency (like using LinearGradientBrush)? The only examples I can find on drawing an image with transparency use ColorMatrix to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is a LinearGradientTextureBrush, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions.

      "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

      B Offline
      B Offline
      BoneSoft
      wrote on last edited by
      #2

      In case anyone cares. Until I find a nicer cleaner way to accomplish this, I've decided to brute force it pixel by pixel. For my purposes, the image is meant to be a background image for a range between 0 and 255. This example does the gradient vertically. To do a different direction, I assume anybody who cares can work out the necessary changes. I'll settle for this only because my image will be very small, but I'd still like to find a more elegant solution.

      private Image GradientTransparent(Image src) {
      Rectangle bmpBox = new Rectangle(0, 0, src.Width, src.Height);
      Bitmap bmp = new Bitmap(src);
      Graphics g = Graphics.FromImage(bmp);
      for (int y = 0; y < bmp.Height; y++) {
      // image is meant to represent a range from 0 to 255
      int alpha = (int)((float)y * 255f / (float)bmp.Height);
      for (int x = 0; x < bmp.Width; x++) {
      Color pixel = bmp.GetPixel(x, y);
      pixel = Color.FromArgb(alpha, pixel);
      bmp.SetPixel(x, y, pixel);
      }
      }
      return bmp;
      }

      "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

      1 Reply Last reply
      0
      • B BoneSoft

        Does anybody have an idea how to draw an image (like using TextureBrush) with gradient transparency (like using LinearGradientBrush)? The only examples I can find on drawing an image with transparency use ColorMatrix to give the entire image a transparency value, which is not what I'm looking for. I guess what I really need is a LinearGradientTextureBrush, which of course doesn't exist. Does anybody have a suggestion on how to accomplish this? I'm out of ideas. Thanks in advance for any suggestions.

        "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

        M Offline
        M Offline
        Manfred Rudolf Bihy
        wrote on last edited by
        #3

        I found something called OpacityMasks here: http://msdn.microsoft.com/en-us/library/ms743320(v=vs.85).aspx#creatingopacitymasks[^], but it seems to be for WPF only so it might not be an option for you. Regards,

        B 1 Reply Last reply
        0
        • M Manfred Rudolf Bihy

          I found something called OpacityMasks here: http://msdn.microsoft.com/en-us/library/ms743320(v=vs.85).aspx#creatingopacitymasks[^], but it seems to be for WPF only so it might not be an option for you. Regards,

          B Offline
          B Offline
          BoneSoft
          wrote on last edited by
          #4

          WPF is outside the scope of this project, but I appreciate the link. It does look interesting. :-D

          "Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown

          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