日期:2014-05-17 浏览次数:20898 次
private void DrawBackgroundImg(Graphics g, Bitmap bmp, byte alpha, int alphaHeight) { //图片的大小 int iWidth = bmp.Width; int iHeight = bmp.Height; int myAlpha = 0; Color color, colorTemp; for (int iRow = 0; iRow < iHeight; iRow++) { for (int iColumn = 0; iColumn < iWidth; iColumn++) { color = bmp.GetPixel(iColumn,iRow); if (iRow > alphaHeight) { myAlpha = alpha; } else { myAlpha = 255; } colorTemp = Color.FromArgb(myAlpha,color); bmp.SetPixel(iColumn,iRow,colorTemp); } } //绘制图形 g.DrawImage(bmp, this.ClientRectangle, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel); }
//以纵坐标100px为分界线 int below100px = 100; //原图 Image imageSrc = new Bitmap(@"xxxxxx"); //新图,在新图上画原图的两个部分 Image imageNew = new Bitmap(imageSrc.Width, imageSrc.Height); //第一部分建立高below100px,坐标为(0,0)的矩形方框 Rectangle part1 = new Rectangle(0, 0, imageSrc.Width, below100px); //第二部分建立高imageSrc.Width-below100px,坐标为(0,below100px)的矩形方框 Rectangle part2 = new Rectangle(0, below100px, imageSrc.Width, imageSrc.Height - below100px); //将原图第一部分设置透明度后画到新图中 Graphics gii = Graphics.FromImage(imageNew); gii.DrawImage(imageSrc, part1, 0, 0, imageSrc.Width, below100px, GraphicsUnit.Pixel, GetImageAttributes(0.9f)); gii.Dispose(); //将原图第二部分设置透明度后画到新图中 Graphics giii = Graphics.FromImage(imageNew); giii.DrawImage(imageSrc, part2, 0, below100px, imageSrc.Width, imageSrc.Height - below100px, GraphicsUnit.Pixel, GetImageAttributes(0.2f)); giii.Dispose();