Second, I've taken an inordinate fondness to the gradient transformation features of IE, which let you create smooth color gradients. (If you've got IE you can see some at work in the World's 2nd Simplest Code Generator (or if you've got Opera/Firefox you can see evidence of the filters in these screen shots.)
And third, I've downloaded firefox, which doesn't render gradient transformations, because those mozilla kids are fairly fussy about standards compliance and things like that.
So I find myself wishing for a browser-independent way of generating color gradients, and thanks to the sparklines article, and sunday's hangover (cheers jeb), I had an idea.
With a little bit of .Net GDI+ magic, I've managed to generate pixel-thin 'blend' images for use as backgrounds.
Basically, a one pixel-wide blend image. Here, i'll stretch it out wide to make it easier to see:
By changing the query string around, you can have any start and end color you want, you can go horizontal or vertical. Plus a few other options.
Like most things in life, this tastes better with CSS. Use the service (or the test page) to create an image for you, then save it to your server. Set it as the background-color (sic.) using CSS. For 'V' (vertical) images, specify a repeat direction of Y. For 'H' (horizontal) images, specify a repeat direction of X.
If parameters are wrongly setup, or if something else goes wrong, you get an image like this one:
Imports System.Drawing
Imports System.Drawing.Drawing2D
...
Private Sub
Page_Load(ByVal sender As System.Object, _
����������� ByVal e As System.EventArgs)
Handles MyBase.Load
��� 'Put user code to
initialize the page here
��� Dim sMessage As String
��� Try
������� 'Parameters:
������� Dim
_Direction As String
'Horizontal or Vertical
������� Dim
_Length As Long
������� Dim _StartColor As String
������� Dim _EndColor As String
������� Dim
_Format As String
������� sMessage
= "retrieving parameters"
������� _Direction = Request.QueryString.Item("Direction")
������� _Length = Request.QueryString.Item("Length")
������� _StartColor =
Request.QueryString.Item("StartColor")
������� _EndColor = Request.QueryString.Item("EndColor")
����� ��_Format = Request.QueryString.Item("Format")
������� Dim lWidth As Integer
������� Dim lHeight As Integer
������� Dim
m_Color1 As Color
������� Dim
m_Color2 As Color
������� Dim myFormat As System.Drawing.Imaging.ImageFormat
��� ����Dim myGradientMode As LinearGradientMode
������� sMessage
= "processing parameters"
������� 'Now use the
parameters
������� If _Direction.ToUpper.StartsWith("H") Then
����������� lWidth = 1
����������� lHeight = _Length
����� ������myGradientMode
= LinearGradientMode.Vertical
������� Else
����������� lWidth = _Length
����������� lHeight = 1
����������� myGradientMode = LinearGradientMode.Horizontal
������� End If
������� If _Format.ToUpper.StartsWith("J") Then
����������� myFormat = Imaging.ImageFormat.Jpeg
������� Else
����������� myFormat = Imaging.ImageFormat.Gif
������� End If
������� sMessage
= "determining colors"
������� m_Color1 = Color.FromArgb(255, _
��������������� CLng("&H" & _StartColor.Substring(0,
2)), _
��������������� CLng("&H" & _StartColor.Substring(2,
2)), _
��������������� CLng("&H" & _StartColor.Substring(4,
2)))
�� �����m_Color2 = Color.FromArgb(255, _
�� �������������CLng("&H" & _EndColor.Substring(0,
2)), _
�� �������������CLng("&H" & _EndColor.Substring(2,
2)), _
�� �������������CLng("&H" & _EndColor.Substring(4,
2)))
�� �����'GO!
�� �����sMessage = "determining
size"
�� �����Dim bmpGradient As New Bitmap(lWidth, lHeight)
������� Dim m_BrushSize As New Rectangle(0, 0, lWidth, lHeight)
������� Dim grBitmap As Graphics = Graphics.FromImage(bmpGradient)
������� sMessage
= "creating gradient brush"
��� ����Dim myLinearGradientBrush As New LinearGradientBrush( _
������������������� m_BrushSize,
m_Color1, m_Color2, _
������������������� myGradientMode)
������� sMessage
= "filling rectangle"
������� grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, _
� �����������������lWidth, lHeight)
� ������sMessage = "saving image to
response stream"
� ������'Write the image to the client!!������������
� ������bmpGradient.Save(Response.OutputStream, myFormat)
� ��Catch ex As System.Exception
� ������Dim bmpGradient As New Bitmap(600, 100)
� ������Dim m_BrushSize As New Rectangle(0, 0, 600, 100)�����������
� ������Dim grBitmap As Graphics = Graphics.FromImage(bmpGradient)
� ������Dim myLinearGradientBrush As New LinearGradientBrush( _
� ��������������m_BrushSize,
_
����� ����������Color.FromArgb(255, 255, 0, 0), _
����� ����������Color.FromArgb(255, 0, 0, 0), _
����� ����������LinearGradientMode.Vertical)
���� ���grBitmap.FillRectangle(myLinearGradientBrush, 0, 0, _
���� �����������600, 100)
���� ���grBitmap.DrawString("Error while " & _
���� �����������sMessage & " for '" & Request.UserHostAddress & _
���� �����������"'." & vbCrLf & ex.Message, _
���� �����������New System.Drawing.Font("Arial", 12, _
���� �����������System.Drawing.FontStyle.Italic),
_
���� �����������System.Drawing.Brushes.White,
10, 12)
���� ���'Write the error message image to the client
���� ���bmpGradient.Save(Response.OutputStream, _
����� ����������System.Drawing.Imaging.ImageFormat.Jpeg)
��� End Try
End Sub