10*10的gif无动画背景透明图片,怎样把他画布大小改变成20*20啊,背景需要透明,是改画布大小啊,不是图像的大小
解决方案 »
- 请教高手有关RS232与RS485协议
- 如何用parallel遍历hashtable
- 急!C#调用另一个project编译生成DLL内的方法时,出现的System.NullReferenceException
- Matlab编译.NET组件问题,急,请达人赐教
- 如何判断与远程服务器上的数据库连接失败
- 帮帮忙! C#中两窗体间的传值
- datagridview中符合条件的行下面画线
- DataList实现分页功能?
- 认识dangdang_9494 (荡荡) 为人..........倒粪高手中的高手...强烈质疑版主管理能力~~~~~~~~~
- 验证码无法显示?
- vs2005自带的水晶报表和2003自带的报表可以兼容吗?? 急。。。在线等!!
- C#入门一题 (很简单。)
画布大小,什么需求?
程序员该死吗?
Bitmap bitmap = new Bitmap(20, 20, Graphics.FromImage(new Bitmap(imagefilename)));
context.Response.ContentType = "Image/GIF";
context.Response.Clear();
context.Response.BufferOutput = true;
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
然后把image的src指向该文件
Bitmap source = new Bitmap("file");
Bitmap bmp = new Bitmap(20,20);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Transparent, 0,0,20,20);
g.DrawImage(source,5,5);
创建一个20*20的Bitmap,然后把gif DrawImage到Bitmap上,然后Bitmap.Save,格式参数选Gif就可以了。
1.用PHOTOSHOP直接修改。
2.用程序代理完成: Bitmap source = new Bitmap("file");
Bitmap bmp = new Bitmap(20,20);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Transparent, 0,0,20,20);
g.DrawImage(source,5,5);
Graphics g = Graphics.FromImage(bit);
//Image img = Image.FromFile(@"D:\tool\2005\demo\battery1.gif");
g.Clear(Color.Transparent);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawImage(bit,0, 0);
bit.Save(@"D:\tool\2005\demo\a.gif",System.Drawing.Imaging.ImageFormat.Gif);
g.Dispose();
//img.Dispose();
bit.Dispose();按照楼上的说法做不行啊 背景还是黑色的
System.Drawing.Bitmap gif = new Bitmap("x:\x.gif");把PictureBox当作画布,图像居中
PictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;背景透明什么意思?
PictureBox.BackColor = System.Drawing.Color.Transparent;这个?大小
PictureBox.Height = gif.Height + 10;
PictureBox.Width = gif.Width + 10;PictureBox.Image = gif;要实现真正的画布就复杂了
Graphics g=Graphics.FromImage(new Bitmap(20,20));
Image image = Image.FromFile(@"C:\Users\Mike\Desktop\bg.gif");
Graphics g = Graphics.FromImage(newImage); g.DrawImage(image, new Rectangle(5, 5, 10, 10),
new Rectangle(0, 0, 10, 10),
GraphicsUnit.Pixel);
newImage.Save(@"C:\Users\Mike\Desktop\bg1.gif");
newImage.Dispose();
image.Dispose();
g.Dispose();
gif是有很多帧,但是作为Image对象打开只能看到第一帧新建的Bitmap当然是不透明的,要手动设置才行。
Bitmap bmp = new Bitmap(20, 20);
for (int i = 0; i < bmp.Width; ++i)
{
for (int j = 0; j < bmp.Height; ++j)
{
bmp.SetPixel(i, j, Color.Transparent);
}
}
Size largeSize,
string imagePath,
string outputImagePath,
Color transparentColor)
{
Image img = Image.FromFile(imagePath);
Bitmap bmp = new Bitmap(largeSize.Width, largeSize.Height);
Graphics graphics = Graphics.FromImage(bmp);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; RectangleF destRect = new RectangleF(
(largeSize.Width - img.Width) / 2.0f,
(largeSize.Height - img.Height) / 2.0f,
img.Width,
img.Height);
RectangleF srcRect = new RectangleF(
-1.0f,
-1.0f,
img.Width + 2,
img.Height + 2); using (SolidBrush brush = new SolidBrush(transparentColor))
{
graphics.FillRectangle(
brush,
0,
0,
largeSize.Width,
largeSize.Height);
} graphics.DrawImage(
img,
destRect,
srcRect,
GraphicsUnit.Pixel); graphics.Flush();
graphics.Dispose(); MakeImage(bmp, outputImagePath);
}
public static void MakeLargeImage(
Size largeSize,
string imagePath,
string outputImagePath,
Color transparentColor)
{
Image img = Image.FromFile(imagePath);
Bitmap bmp = new Bitmap(largeSize.Width, largeSize.Height);
Graphics graphics = Graphics.FromImage(bmp);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; Rectangle destRect = new Rectangle(
(largeSize.Width - img.Width) / 2,
(largeSize.Height - img.Height) / 2,
img.Width,
img.Height);
Rectangle srcRect = new Rectangle(
0,
0,
img.Width,
img.Height); using (SolidBrush brush = new SolidBrush(transparentColor))
{
graphics.FillRectangle(
brush,
-1,
-1,
largeSize.Width + 2,
largeSize.Height + 2);
} graphics.DrawImage(
img,
destRect,
srcRect,
GraphicsUnit.Pixel); graphics.Flush();
graphics.Dispose(); MakeImage(bmp, outputImagePath);
}
http://blog.csdn.net/zgke/archive/2008/11/28/3401077.aspx
如果写代码的话
Color c = Color.FromArgb(0x66666666);
Bitmap b = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
for(int x = 0; x < 100; x++)
{
for(int y = 0; y < 100; y++)
{
b.SetPixel(x, y, c);
}
}
this.pictureBox1.Image = b;