C设置图像透明度.doc
文本预览下载声明
float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, opacity, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix matrix = new ColorMatrix(nArray);
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap )
Image srcImage = Image.FromFile(aaa.jpg);
Bitmap resultImage = new Bitmap(srcImage.Width, srcImage.Height);
Graphics g = Graphics.FromImage(resultImage);
g.DrawImage( srcImage, new Rectangle( 0, 0, srcImage.Width, srcImage.Height ), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes);
/// summary?/// Creating a Watermarked Photograph with GDI+ for .NET??/// /summary??/// param name=rSrcImgPath原始图片的物理路径/param??/// param name=rMarkImgPath水印图片的物理路径/param??/// param name=rMarkText水印文字(不显示水印文字设为空串)/param??/// param name=rDstImgPath输出合成后的图片的物理路径/param??/// @整理:anyrock@mending.cn??public void BuildWatermark(string rSrcImgPath,string rMarkImgPath,string rMarkText,string rDstImgPath)??{?????? //以下(代码)从一个指定文件创建了一个Image 对象,然后为它的 Width 和 Height定义变量。?????? //这些长度待会被用来建立一个以24 bits 每像素的格式作为颜色数据的Bitmap对象。?????? Image imgPhoto = Image.FromFile(rSrcImgPath);?????? int phWidth = imgPhoto.Width;?????? int phHeight = imgPhoto.Height;?????? Bitmap bmPhoto=new Bitmap(phWidth,phHeight, PixelFormat.Format24bppRgb);?????? bmPhoto.SetResolution(72,72);?????? Graphics grPhoto = Graphics.FromImage(bmPhoto);?????? //这个代码载入水印图片,水印图片已经被保存为一个BMP文件,以绿色(A=0,R=0,G=255,B=0)作为背景颜色。?????? //再一次,会为它的Width 和Height定义一个变量。?????? Image imgWatermark = new Bitmap(rMarkImgPath);?????? int wmWidth = imgWatermark.Width;?????? int wmHeight = imgWatermark.Height;?????? //这个代码以100%它的原始大小绘制imgPhoto 到Graphics 对象的(x=0,y=0)位置。?????? //以后所有的绘图都将发生在原来照片的顶部。?????? grPhoto.SmoothingMode = SmoothingMode.AntiAlias;?????? grPhoto.DrawImage(??????????? imgPhoto,????????????????????????????????????????????????? new Rectangle(0, 0
显示全部