我如何利用C#制作梯度图像(带有一定高度和安度;宽度、起色和端肤色)? 是否有任何人有一个简单的样本。 谢谢!
C# 生成梯度图像
原标题:C# Create Gradient Image
最佳回答
您可使用。 例如
// using System.Drawing;
// using System.Drawing.Imaging;
// using System.Drawing.Drawing2D;
public static void OutputGradientImage()
{
using (Bitmap bitmap = new Bitmap(100, 100)) // 100x100 pixels
using (Graphics graphics = Graphics.FromImage(bitmap))
using (LinearGradientBrush brush = new LinearGradientBrush(
new Rectangle(0, 0, 100, 100),
Color.Blue,
Color.Red,
LinearGradientMode.Vertical))
{
brush.SetSigmaBellShape(0.5f);
graphics.FillRectangle(brush, new Rectangle(0, 0, 100, 100));
bitmap.Save("gradientImage.jpg", ImageFormat.Jpeg);
}
}
问题回答
Linear Graient 这里的朋友是:
Bitmap bmp = new Bitmap(Width, Height);
Graphics g = Graphics.FromImage(bmp);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(0, 0), new Point(Width, Height), Color.Black, Color.Red);
g.FillRectangle(lgb, 0, 0, Width, Height);
bmp.Save("FileName");
lgb.Dispose();
g.Dispose();
bmp.Dispose();
protected override void OnPaintBackground(PaintEventArgs e)
{
using (Brush b = new LinearGradientBrush(ClientRectangle, Color.Red, Color.Blue, LinearGradientMode.ForwardDiagonal))
e.Graphics.FillRectangle(b, ClientRectangle);
}
这简明扼要。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding