今天突发奇想,想做各Photoshop的软件开启界面,因为它不但是不规则图形,而且还有阴影,呵呵,没的说先Google一下,果然出来N多资料,
简单的想了一下,应该是用图形处理软件处理好图形,包括了投影,然后再用GDI绘图给绘制出来,嗯,应该是这么干的,先自己写各吧!
效果只有2个字:很丑
圆型的边角没有处理成透明的,很郁闷呀~!
上网搜罗了下,看到博客圆里面有为大哥弄过,那位记不得了,先借代码来用用,:-)
在Load事件里面再
BitmapRegion bitmapregion = new BitmapRegion();
BitmapRegion.CreateControlRegion(this, new Bitmap("face2.png"));
两句话就搞定了,o(∩_∩)o...,高手就是高手,可惜原来是外国人写的呢!感慨下~!
处理过后的图片就变成了圆边了,不过想要实现想PS那种启动效果,哎,估计比较难~!实际也比较难~!
不过,就在我打写这篇文章的时候,突然想到,能不能获取图片的左下角像素,分别以45°方向延展几个像素,颜色用黑色渐变,这样不就成了投影了吗???不过得先获取边缘,同时投的影不能盖到图片上,可以先投影,后画图,嗯好主意,那位大哥能实践一下就好咯~ ~!
简单的想了一下,应该是用图形处理软件处理好图形,包括了投影,然后再用GDI绘图给绘制出来,嗯,应该是这么干的,先自己写各吧!
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
DrawCustomActivity(e);
}
private void DrawCustomActivity(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Bitmap bmp = new Bitmap("face.jpg");
//bmp.MakeTransparent(this.TransparencyKey);
//Image img = Image.FromFile("face.png", false);
//this.Width = img.Width;
//this.Height = img.Height;
graphics.DrawImageUnscaledAndClipped(bmp, new Rectangle(0, 0, 541, 354));
}
嗯,把窗体给改造一下,不许显示边框,不许显示控制栏,嗯,然后重写了它的OnPaint事件,呵呵,可以看到效果咯{
//base.OnPaint(e);
DrawCustomActivity(e);
}
private void DrawCustomActivity(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Bitmap bmp = new Bitmap("face.jpg");
//bmp.MakeTransparent(this.TransparencyKey);
//Image img = Image.FromFile("face.png", false);
//this.Width = img.Width;
//this.Height = img.Height;
graphics.DrawImageUnscaledAndClipped(bmp, new Rectangle(0, 0, 541, 354));
}
效果只有2个字:很丑
圆型的边角没有处理成透明的,很郁闷呀~!
上网搜罗了下,看到博客圆里面有为大哥弄过,那位记不得了,先借代码来用用,:-)
public class BitmapRegion
{
public BitmapRegion()
{ }
public static void CreateControlRegion(Control control, Bitmap bitmap)
{
if (control == null || bitmap == null)
return;
control.Width = bitmap.Width;
control.Height = bitmap.Height;
if (control is System.Windows.Forms.Form)
{
Form form = (Form)control;
form.Width = control.Width;
form.Height = control.Height;
form.FormBorderStyle = FormBorderStyle.None;
form.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
form.Region = new Region(graphicsPath);
}
else if (control is System.Windows.Forms.Button)
{
Button button = (Button)control;
button.Text = "";
button.Cursor = Cursors.Hand;
button.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
button.Region = new Region(graphicsPath);
}
}
private static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
{
GraphicsPath graphicsPath = new GraphicsPath();
//使用坐上角第一个点作为透明色
Color colorTransparent = bitmap.GetPixel(0, 0);
int colOpaquePixel = 0;
for (int row = 0; row < bitmap.Height; row++)
{
colOpaquePixel = 0;
for (int col = 0; col < bitmap.Width; col++)
{
if (bitmap.GetPixel(col, row) != colorTransparent)
{
colOpaquePixel = col;
int colNext = col;
for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++)
{
if (bitmap.GetPixel(colNext, row) == colorTransparent)
break;
}
graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
col = colNext;
}
}
}
return graphicsPath;
}
}
写了2个类来处理图片,选择图片的左上角的像素作为要透明的像素,然后开始透明与这个相似的像素,{
public BitmapRegion()
{ }
public static void CreateControlRegion(Control control, Bitmap bitmap)
{
if (control == null || bitmap == null)
return;
control.Width = bitmap.Width;
control.Height = bitmap.Height;
if (control is System.Windows.Forms.Form)
{
Form form = (Form)control;
form.Width = control.Width;
form.Height = control.Height;
form.FormBorderStyle = FormBorderStyle.None;
form.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
form.Region = new Region(graphicsPath);
}
else if (control is System.Windows.Forms.Button)
{
Button button = (Button)control;
button.Text = "";
button.Cursor = Cursors.Hand;
button.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
button.Region = new Region(graphicsPath);
}
}
private static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
{
GraphicsPath graphicsPath = new GraphicsPath();
//使用坐上角第一个点作为透明色
Color colorTransparent = bitmap.GetPixel(0, 0);
int colOpaquePixel = 0;
for (int row = 0; row < bitmap.Height; row++)
{
colOpaquePixel = 0;
for (int col = 0; col < bitmap.Width; col++)
{
if (bitmap.GetPixel(col, row) != colorTransparent)
{
colOpaquePixel = col;
int colNext = col;
for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++)
{
if (bitmap.GetPixel(colNext, row) == colorTransparent)
break;
}
graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
col = colNext;
}
}
}
return graphicsPath;
}
}
在Load事件里面再
BitmapRegion bitmapregion = new BitmapRegion();
BitmapRegion.CreateControlRegion(this, new Bitmap("face2.png"));
两句话就搞定了,o(∩_∩)o...,高手就是高手,可惜原来是外国人写的呢!感慨下~!
处理过后的图片就变成了圆边了,不过想要实现想PS那种启动效果,哎,估计比较难~!实际也比较难~!
不过,就在我打写这篇文章的时候,突然想到,能不能获取图片的左下角像素,分别以45°方向延展几个像素,颜色用黑色渐变,这样不就成了投影了吗???不过得先获取边缘,同时投的影不能盖到图片上,可以先投影,后画图,嗯好主意,那位大哥能实践一下就好咯~ ~!