我有一张图片,想在图片的固定位置插一些文字,有没有实现的例子
解决方案 »
- ASP.NET上传图片的问题。img使用绝对路劲不能显示图片的问题
- 电子地图制作
- 现在要在.net中要将数据读出到excels 并且要按自己的要求显示在excels 中,可以通过应用程序读出也可以通过asp页面读出。格式如下:
- 有关File.Exists(filename)的问题
- 请问如果程序里引用了oracle.clinet,是不是发布asp.net程序的应用程序服务器中就一定要装oracle客户端呢???
- web页面(webform)中向ocx控件传参数问题 谢谢
- 数据库open错误 求解!
- 怎样得到Access数据库中字段的数据类型(比如:只读字段,自动编号)
- 明天要去面试。。不知道会考些什么题目????
- 在datagrid里加入了一个模板列,,,是textbox的,那怎么对textbox进行操作!!对其text属性进行读写???
- javascript 未找到对象
- IIS无法启动!
网上有很多这样现成的控件,你也可以用代码:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
namespace swfuploadtest
{
/// <summary>
/// Summary description for WaterMark2.
/// </summary>
/*
*示例
string wmFilePath = Server.MapPath(".") + "\\water.gif";
string srcFilePath = Server.MapPath(".") + "\\aug.jpg";
string srcnewpath = Server.MapPath(".") + "\\augnew.jpg";
using (System.Drawing.Image wmImg = System.Drawing.Image.FromFile(wmFilePath))
{
System.Drawing.Image srcImg = System.Drawing.Image.FromFile(srcFilePath);
WaterMark wm = new WaterMark(srcImg, wmImg); wm.Alignment = ContentAlignment.TopLeft;
using (Graphics graphics = wm.GetWaterMarkImage())
{
graphics.DrawImage(srcImg, srcImg.Width, srcImg.Height); Bitmap bitmap1 = new Bitmap(srcImg); //保存图片到指定路径
//bitmap1.Save(srcnewpath, ImageFormat.Bmp); //图片输出出来
MemoryStream stream1 = new MemoryStream();
bitmap1.Save(stream1, ImageFormat.Bmp);
Response.ClearContent();
Response.ContentType = "image/Bmp";
Response.BinaryWrite(stream1.ToArray());
}
}
*/
public class WaterMark
{
private Image m_SrcImg;
private Image m_WMImg;
private ContentAlignment m_ImagePosition; #region 公有属性 public ContentAlignment Alignment
{
set
{
m_ImagePosition = value;
}
} #endregion #region 构造函数 public WaterMark(Image srcImg, Image wmImg)
{
m_SrcImg = srcImg;
m_WMImg = wmImg; m_ImagePosition = ContentAlignment.BottomRight;
} #endregion #region 公有方法 public Graphics GetWaterMarkImage()
{
Graphics outGraphics = Graphics.FromImage(m_SrcImg);
int phWidth = m_SrcImg.Width;
int phHeight = m_SrcImg.Height; //To achieve a transulcent water we will apply (2) color
//manipulations by defineing a ImageAttributes object and
//seting (2) of its properties.
ImageAttributes imageAttributes = new ImageAttributes(); //The first step in manipulating the water image is to replace
//the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)
//to do this we will use a Colormap and use this to define a RemapTable
ColorMap colorMap = new ColorMap(); //My water was defined with a background of 100% Green this will
//be the color we search for and replace with transparency
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); ColorMap[] remapTable = {colorMap}; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); //The second color manipulation is used to change the opacity of the
//water. This is done by applying a 5x5 matrix that contains the
//coordinates for the RGBA space. By setting the 3rd row and 3rd column
//to 0.3f we achive a level of opacity
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.9f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); //create a image object containing the water
if(m_WMImg != null)
{
int wmWidth = m_WMImg.Width;
int wmHeight = m_WMImg.Height; //For this example we will place the water in the upper right
//hand corner of the photograph. offset down 10 pixels and to the
//left 10 pixles int xPosOfWm = 0;
int yPosOfWm = 0; switch(m_ImagePosition)
{
case ContentAlignment.BottomCenter:
xPosOfWm = (phWidth/2) - (wmWidth/2);
yPosOfWm = (phHeight - wmHeight) - 10;
break; case ContentAlignment.BottomLeft:
xPosOfWm = 10;
yPosOfWm = (phHeight - wmHeight) - 10;
break; case ContentAlignment.BottomRight:
xPosOfWm = ((phWidth - wmWidth)-10);
yPosOfWm = (phHeight - wmHeight) - 10;
break; case ContentAlignment.MiddleCenter:
xPosOfWm = (phWidth/2) - (wmWidth/2);
yPosOfWm = (phHeight/2) - (wmHeight/2);
break; case ContentAlignment.MiddleLeft:
xPosOfWm = 10;
yPosOfWm = (phHeight/2) - (wmHeight/2);
break; case ContentAlignment.MiddleRight:
xPosOfWm = ((phWidth - wmWidth)-10);
yPosOfWm = (phHeight/2) - (wmHeight/2);
break; case ContentAlignment.TopCenter:
xPosOfWm = (phWidth/2) - (wmWidth/2);
yPosOfWm = 10;
break; case ContentAlignment.TopLeft:
xPosOfWm = 10;
yPosOfWm = 10;
break; case ContentAlignment.TopRight:
//For this example we will place the water in the upper right
//hand corner of the photograph. offset down 10 pixels and to the
//left 10 pixles xPosOfWm = ((phWidth - wmWidth)-10);
yPosOfWm = 10;
break; } outGraphics.DrawImage(m_WMImg,
new Rectangle(xPosOfWm,yPosOfWm,wmWidth,wmHeight), //Set the detination Position
0, // x-coordinate of the portion of the source image to draw.
0, // y-coordinate of the portion of the source image to draw.
wmWidth, // Water Width
wmHeight, // Water Height
GraphicsUnit.Pixel, // Unit of measurment
imageAttributes); //ImageAttributes Object
} return outGraphics;
} #endregion