posted on Sunday, January 11, 2004 11:47 PM
by
taylorza
Fun with Colors
Now there are a few things that I am definitely not, and number 1 is artistic, number 2 a HTML/CSS guru, give me server side code any day. So given that, you will excuse my pride in my meager achievement at customizing my blog. One interesting thing that did come out of it was what I did with the banner. Seen that my wife really liked the heading bitmap of the 'Lighty - Custom Css' I wanted to include that in my customized look, but the colors just did not fit. So first thing I thought was to find a tool to convert from one shade of color to another, and there we find something else that I am just no good at and that is using tools. So eventually I decided to write a little tool to do the conversion.
The Tool
Wondered about what algorithm I could use, I figured that converting the RGB values to HSL and then just changing the H value might be a possible solution. While thinking on this it struck me, wait this is a really easy problem in this case. I want to convert from shades of orange to shades of blue and there are no other colors other than white. Now shades of orange have relatively high red (R) values and low blue (B) values, so it occurred to me to just swap the R and B values for each pixel and well as you can see that worked pretty well.
Since I had a VB.NET project open (Preparing for a lecture), I quickly hacked some VB code into the Paint event and ran the application, end result a cool blue header. Now if anybody wants to tell me about some cool (preferably free, and easy to use) tools I would be grateful and any artistic criticisms are welcome.
The Code
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim x, y As Integer
Dim bmp As New Bitmap("C:\images\header.jpg")
For x = 0 To bmp.Width - 1
For y = 0 To bmp.Height - 1
Dim c As Color = bmp.GetPixel(x, y)
bmp.SetPixel(x, y, Color.FromArgb(c.B, c.G, c.R))
Next
Next
bmp.Save("C:\images\header.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
End Sub
BTW: I used a Windows port of The GIMP to convert the BMP to a GIF.