#region 添加水印图片
/// <summary>
/// 添加水印图片
/// </summary>
/// <param name="newwaterimage">imge 对象</param>
/// <param name="WaterMarkPicPath">水印图片的地址</param>
/// <param name="_width">水印位置</param>
private static void AddWaterImage(System.Drawing.Image newwaterimage, string WaterMarkPicPath,ImageWaterPosition warterposition)
{
int _width = newwaterimage.Width;
int _height = newwaterimage.Height;
Graphics picture = Graphics.FromImage(newwaterimage);
Image water = new Bitmap(WaterMarkPicPath);
ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap();
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
int xpos = 0;
int ypos = 0;
int WaterWidth = 0;
int WaterHeight = 0;
double bl = 1d;
//计算水印图片的比率
//取背景的1/4宽度来比较
if ((_width > water.Width * 4) && (_height > water.Height * 4))
{
bl = 1;
}
else if ((_width > water.Width * 4) && (_height < water.Height * 4))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(water.Height);
}
else
{
if ((_width < water.Width * 4) && (_height > water.Height * 4))
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(water.Width);
}
else
{
if ((_width * water.Height) > (_height * water.Width))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(water.Height);
}
else
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(water.Width);
}
}
}
WaterWidth = Convert.ToInt32(water.Width * bl);
WaterHeight = Convert.ToInt32(water.Height * bl);
switch (warterposition)
{
case ImageWaterPosition.WM_TOP_LEFT:
xpos = 10;
ypos = 10;
break;
case ImageWaterPosition.WM_TOP_RIGHT:
xpos = _width - WaterWidth - 10;
ypos = 10;
break;
case ImageWaterPosition.WM_BOTTOM_RIGHT:
xpos = _width - WaterWidth - 10;
ypos = _height - WaterHeight - 10;
break;
case ImageWaterPosition.WM_BOTTOM_LEFT:
xpos = 10;
ypos = _height - WaterHeight - 10;
break;
}
picture.DrawImage(water, new Rectangle(xpos, ypos, WaterWidth, WaterHeight), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel, imageAttributes);
water.Dispose();
imageAttributes.Dispose();
picture.Dispose();
}
#endregion
现在的水印是透明的,,我不想让它透明,怎么改。
/// <summary>
/// 添加水印图片
/// </summary>
/// <param name="newwaterimage">imge 对象</param>
/// <param name="WaterMarkPicPath">水印图片的地址</param>
/// <param name="_width">水印位置</param>
private static void AddWaterImage(System.Drawing.Image newwaterimage, string WaterMarkPicPath,ImageWaterPosition warterposition)
{
int _width = newwaterimage.Width;
int _height = newwaterimage.Height;
Graphics picture = Graphics.FromImage(newwaterimage);
Image water = new Bitmap(WaterMarkPicPath);
ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap();
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
int xpos = 0;
int ypos = 0;
int WaterWidth = 0;
int WaterHeight = 0;
double bl = 1d;
//计算水印图片的比率
//取背景的1/4宽度来比较
if ((_width > water.Width * 4) && (_height > water.Height * 4))
{
bl = 1;
}
else if ((_width > water.Width * 4) && (_height < water.Height * 4))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(water.Height);
}
else
{
if ((_width < water.Width * 4) && (_height > water.Height * 4))
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(water.Width);
}
else
{
if ((_width * water.Height) > (_height * water.Width))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(water.Height);
}
else
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(water.Width);
}
}
}
WaterWidth = Convert.ToInt32(water.Width * bl);
WaterHeight = Convert.ToInt32(water.Height * bl);
switch (warterposition)
{
case ImageWaterPosition.WM_TOP_LEFT:
xpos = 10;
ypos = 10;
break;
case ImageWaterPosition.WM_TOP_RIGHT:
xpos = _width - WaterWidth - 10;
ypos = 10;
break;
case ImageWaterPosition.WM_BOTTOM_RIGHT:
xpos = _width - WaterWidth - 10;
ypos = _height - WaterHeight - 10;
break;
case ImageWaterPosition.WM_BOTTOM_LEFT:
xpos = 10;
ypos = _height - WaterHeight - 10;
break;
}
picture.DrawImage(water, new Rectangle(xpos, ypos, WaterWidth, WaterHeight), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel, imageAttributes);
water.Dispose();
imageAttributes.Dispose();
picture.Dispose();
}
#endregion
现在的水印是透明的,,我不想让它透明,怎么改。
解决方案 »
- excel导入sql2005,数字和文本杂合的列的只导入了数字数据,文本列为空
- vs2005中开发ASP.net网站,怎样进行页面布局
- 弹出层的问题
- asp.net内容怎么保持网页形式!
- .net 一个小问题 高手赐教
- asp.net中如何在选择出来的数据的基础上在选择出符合条件的数据
- datagrid中自定义按钮,点击进入下一个页面,根据点击行的信息在下个页面中显示
- 可能是权限问题,请高手帮忙解决
- 在线等待!为什么连不上sqlserver?谁能告诉我?
- 求问大神门 Asp.net Textbox 怎么自定义name??????
- 用链接?传值有没有 字符数的限制?
- DetailViews 哪个属性 让控件变成可编辑
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
matrix矩阵,红色的参数是可以改透明度的。