Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I wih to create an image to load as a background in a header on an html page that consists of a gradient from dark to lighter blue.

Short of proprietry graphics packages, is there a simple way (ie free?) of achieving this?


similar to these[^]
Posted

This[^] looks promising.
Otherwise there's plenty of other sites, just Google 'gradient creator'. :)

DD says...WooHoo that is not only exactly what I want, but the first little go I had, guessing at a couple numbers, got the right effect!

From KS: Glad to hear you found it useful. :thumbsup:
 
Share this answer
 
v3
Hi Dave,

It seems from the answer above that you're sorted, but just thought I'd offer another possible solution.

How about doing it in code? You could create a new Bitmap, draw onto it using a Graphics object (obtained using Graphics.FromImage(bitmap)), then save the bitmap to file in your desired format.

DD Says...Sounds rather more complicated than my current envelope of ability would allow, but not beyond my horizon of potential, I shall investigate this.
Thanks though, you have put another project on my list of things to learn. The more the merrier.

Hi again Dave,

I've just had a play to make sure it was as easy as I thought and it is!
I don't have VB installed here, but here's the C# code - should be easy enough to convert.
C#
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
public static class GradientCreator
{
    public static void CreateGradientBitmap(Size size, Color color1, Color color2, float angle, string filename, ImageFormat format)
    {
        Rectangle fillRectangle = new Rectangle(0, 0, size.Width, size.Height);
        Bitmap b = new Bitmap(size.Width, size.Height);
        Graphics g = Graphics.FromImage(b);
        Brush gradientBrush = new LinearGradientBrush(fillRectangle, color1, color2, angle);
        g.FillRectangle(gradientBrush, fillRectangle);
        try
        {
            b.Save(filename);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        finally
        {
            gradientBrush.Dispose();
            g.Dispose();
            b.Dispose();
        }
    }
}
Can be called something like:
C#
GradientCreator.CreateGradientBitmap(new Size(100, 100), Color.DarkBlue, Color.LightBlue, 90f, imagePath, ImageFormat.Jpeg);
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900