图像的颜色渐变 [英] colour gradient for image

查看:129
本文介绍了图像的颜色渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在html页面的标题中创建一个图像作为背景加载,该页面由从深蓝色到浅蓝色的渐变组成.

缺少专有图形包,有没有简单的方法(即免费?)来实现这一目标?


类似于这些 [

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[^]

推荐答案

[ ^ ]看起来很有希望.
否则,还有很多其他网站,只有Google的梯度创建者". :)

DD表示... WooHoo不仅是我想要的,而且是我的第一个尝试,猜了几个数字,都得到了正确的效果!

来自KS:很高兴听到您发现它很有用. :thumbsup:
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:


戴夫,

从上面的答案看来,您已经过排序,但只是认为我会提供另一种可能的解决方案.

用代码怎么做?您可以创建一个新的Bitmap,使用Graphics对象(使用Graphics.FromImage(bitmap)获取)在其上绘制,然后以所需的格式将位图保存到文件中.

DD说...听起来比我当前的能力范围要复杂得多,但我不会超出我的潜力范围,我将对此进行调查.
不过,谢谢,您已将另一个项目放在我要学习的东西上.越多越好.

戴夫,

我刚刚进行了一场戏,以确保它像我想的那样简单而且确实如此!
我没有在这里安装VB,但是这里是C#代码-应该足够容易转换.
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();
        }
    }
}

可以这样称呼:

GradientCreator.CreateGradientBitmap(new Size(100, 100), Color.DarkBlue, Color.LightBlue, 90f, imagePath, ImageFormat.Jpeg);


这篇关于图像的颜色渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆