怎么设透明背景?
个位高手,我把一个图片拉伸变形之后,想把它的背景弄成透明的,然后保存
代码是这么写的:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.Image Image1;
private void Page_Load(object sender, System.EventArgs e)
{
//显示拉伸之前
Image1.ImageUrl = "snoopy.jpg";
Image1.Height = 100;
Image1.Width = 150;
System.Drawing.Bitmap img = new Bitmap (@"c:\inetpub\wwwroot\imgtra\snoopy.jpg");
System.Drawing.Bitmap img2 = new Bitmap (img.Width,img.Height +img.Width,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
for (int i = 0; i < img.Width ;i++)
{//拉伸
for (int t = 0; t < img2.Height ; t++) img2.SetPixel (i,t,Color.Transparent ); //这句把底色弄成透明
for (int j = i; (j - i) < img.Height ; j++)
{
img2.SetPixel (i,j,img.GetPixel(i,j-i));
}
}
img2.Save (@"c:\inetpub\wwwroot\imgtra\a.jpg",img.RawFormat);
//显示拉伸之后
Image2.ImageUrl = "a.jpg";
Image2.Height = 200;
Image2.Width = 100;
}
结果存下来的图片背景是白色,不是透明,而且图片原来的透明部分也变成白色了……
应改怎么改啊?谢谢各位啦~~~~~~~~~~~~~