Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML graphics
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 19-Apr-10 11:06am
Dalek Dave432.8K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This[^] looks promising.
Otherwise there's plenty of other sites, just Google 'gradient creator'. Smile | :)
 
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. Thumbs Up | :thumbsup:
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
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:
GradientCreator.CreateGradientBitmap(new Size(100, 100), Color.DarkBlue, Color.LightBlue, 90f, imagePath, ImageFormat.Jpeg);
  Permalink  
v4

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 20 Apr 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100