WEB开发网
开发学院WEB开发ASP.NET c#给图片添加文字 阅读

c#给图片添加文字

 2012-11-16 20:54:13 来源:WEB开发网   
核心提示:imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);int xpos = 0;int ypos = 0;int WatermarkWidth = 0;int WatermarkHeigh

imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

int xpos = 0;
int ypos = 0;
int WatermarkWidth = 0;
int WatermarkHeight = 0;
double bl = 1d;
//计算水印图片的比率
//取背景的1/4宽度来比较
if ((_width > watermark.Width * 4) && (_height > watermark.Height * 4))
{
bl = 1;
}
else if ((_width > watermark.Width * 4) && (_height < watermark.Height * 4))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(watermark.Height);

}
else

if ((_width < watermark.Width * 4) && (_height > watermark.Height * 4))
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(watermark.Width);
}
else
{
if ((_width * watermark.Height) > (_height * watermark.Width))
{
bl = Convert.ToDouble(_height / 4) / Convert.ToDouble(watermark.Height);

}
else
{
bl = Convert.ToDouble(_width / 4) / Convert.ToDouble(watermark.Width);

}

}

WatermarkWidth = Convert.ToInt32(watermark.Width * bl);
WatermarkHeight = Convert.ToInt32(watermark.Height * bl);

switch (_watermarkPosition)
{
case "WM_TOP_LEFT":
xpos = 10;
ypos = 10;
break;
case "WM_TOP_RIGHT":
xpos = _width - WatermarkWidth - 10;
ypos = 10;
break;
case "WM_BOTTOM_RIGHT":
xpos = _width - WatermarkWidth - 10;
ypos = _height - WatermarkHeight - 10;
break;
case "WM_BOTTOM_LEFT":
xpos = 10;
ypos = _height - WatermarkHeight - 10;
break;
}

picture.DrawImage(watermark, new Rectangle(xpos, ypos, WatermarkWidth, WatermarkHeight), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes);


watermark.Dispose();
imageAttributes.Dispose();
}

/// <summary>
/// 生成缩略图
/// </summary>
/// <param name="oldpath">原图片地址</param>
/// <param name="newpath">新图片地址</param>
/// <param name="tWidth">缩略图的宽</param>
/// <param name="tHeight">缩略图的高</param>
private void GreateMiniImage(string oldpath, string newpath, int tWidth, int tHeight)
{

try
{

System.Drawing.Image image = System.Drawing.Image.FromFile(oldpath);
double bl = 1d;
if ((image.Width <= image.Height) && (tWidth >= tHeight))
{
bl = Convert.ToDouble(image.Height) / Convert.ToDouble(tHeight);
}
else if ((image.Width > image.Height) && (tWidth < tHeight))
{
bl = Convert.ToDouble(image.Width) / Convert.ToDouble(tWidth);

}
else

if ((image.Width <= image.Height) && (tWidth <= tHeight))
{
if (image.Height / tHeight >= image.Width / tWidth)
{
bl = Convert.ToDouble(image.Width) / Convert.ToDouble(tWidth);

}
else
{
bl = Convert.ToDouble(image.Height) / Convert.ToDouble(tHeight);
}

上一页  1 2 3 4  下一页

Tags:图片 添加 文字

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接