|
-
Apr 23rd, 2013, 10:08 AM
#1
Thread Starter
New Member
How can I shade an image with a color?
First, let me say this: I'm not making an image editing program. What I'm doing is attempting to replace an image's shade with another color.
Here's exactly what's happening. Say I have a .bmp, .jpg, .png, whatever sitting on a form at design time. The form's background is black, and so is most of the image I'm talking about. The area that needs to be shaded is the white area of that image. So imagine it's an image of the letter "A". The A is white, everything else is black. How can I throw a color at that, be it hex or rgb, doesn't matter, and make the white area of that image that color? I need to be able to do this at design time.
Thanks!
-
Apr 23rd, 2013, 10:22 AM
#2
Re: How can I shade an image with a color?
At design time? Are you sure abou that? It certainly makes it easier, as you can do it in Paint (or the free Paint.NET, which is pretty good). Basically, any drawing program will probably have a floodfill tool, which may be all you need.
My usual boring signature: Nothing
 
-
Apr 23rd, 2013, 10:24 AM
#3
Thread Starter
New Member
Re: How can I shade an image with a color?
 Originally Posted by Shaggy Hiker
At design time? Are you sure abou that? It certainly makes it easier, as you can do it in Paint (or the free Paint.NET, which is pretty good). Basically, any drawing program will probably have a floodfill tool, which may be all you need.
Yes, definitely at design time. What is happening is that I have a series of buttons that change border colors based on the color used, and I want that image to also change beside it. I would use it as a ding font or something so I could easily change it, but this particular symbol does not exist as a ding, so I had to make it an image. I guess that's exactly what I'm looking for, "how to flood a picture with a color at design time."
-
Apr 23rd, 2013, 10:25 AM
#4
Thread Starter
New Member
Re: How can I shade an image with a color?
I'm sorry, I mean to say I want it done at RUN TIME!! Not design time, that's silly.
-
Apr 23rd, 2013, 12:59 PM
#5
Re: How can I shade an image with a color?
I kind of thought you meant that.
I've moved over to using XNA, which is totally different when it comes to tinting a location. Here's a function given to me by .Paul. on this very forum.
Code:
Protected Function changeBrightness(ByVal outputImage As Image) As Bitmap
Dim brightness As Single = 1.25
Dim contrast As Single = 1.0F ' no change in contrast
Dim adjustedBrightness As Single = brightness - 1.0F
'create matrix that will brighten and contrast the image
Dim image_attr As New System.Drawing.Imaging.ImageAttributes
Dim cm As System.Drawing.Imaging.ColorMatrix = New System.Drawing.Imaging.ColorMatrix(New Single()() _
{ _
New Single() {contrast, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, contrast, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, contrast, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
New Single() {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0.0, 1.0}})
Dim rect As Rectangle = _
Rectangle.Round(outputImage.GetBounds(GraphicsUnit.Pixel))
Dim wid As Integer = outputImage.Width
Dim hgt As Integer = outputImage.Height
Dim img As New Bitmap(wid, hgt)
Dim gr As Graphics = Graphics.FromImage(img)
image_attr.SetColorMatrix(cm)
gr.DrawImage(outputImage, rect, 0, 0, wid, hgt, GraphicsUnit.Pixel, image_attr)
gr.Dispose()
Return img
End Function
Whether this will work for you, or can be modified to work for you, I'm not sure. What I was doing with this was changing an image such that I would have a selected vs normal image. It changes the brightness, but it may give you leads for other types of changes, as well. If it is possible, don't do this on the fly. Take the initial image and change it to create a new image, and store both of those. The technique is fast enough that you can do a few images on the fly, but this is really set up to make changed images for caching purposes.
This may be the first time that code provided by one member was resupplied by that member to another for reuse. I'm not even sure whether I changed the original code .Paul. wrote, or in what way. You might be able to find the thread around here if you were curious, as it would be one I started.
My usual boring signature: Nothing
 
-
Apr 23rd, 2013, 01:00 PM
#6
Thread Starter
New Member
Re: How can I shade an image with a color?
I appreciate your assistance. I'll give that a shot, shouldn't be too much change.
-
Apr 23rd, 2013, 01:12 PM
#7
Re: How can I shade an image with a color?
You might also find this thread useful.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 23rd, 2013, 02:11 PM
#8
Thread Starter
New Member
Re: How can I shade an image with a color?
Thank you dunfiddlin, that code by Paul was precisely what I was looking for.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|