Upload | Upload image graphics DrawImage method, define a variety of prototypes, you can draw the specified image object in place. Using this method, you can draw a watermark picture on a picture object. Combined with freetextbox convenient picture upload function, can realize a picture news system suitable for more pictures. The following watermark method takes the parameter as the file stream, the original picture name, the watermark picture name, the picture saves the path and so on, corresponding annotation understanding code should not have the big problem.
-----------------------------------------------------------------
public void Watermark (Stream inputstream, String fileName, String
Markname, String Picpath)
{
String workingdirectory =
HttpContext.Current.Request.PhysicalApplicationPath + "\" + Picpath;
Stream photostream = InputStream;
string watermarkname = Markname;
string photofinalname = FileName;
Create a Image object containing the photograph to watermark
System.Drawing.Image Imgphoto = System.Drawing.Image.FromStream (photostream);
int phwidth = Imgphoto.width;
int phheight = Imgphoto.height;
Create a Image object containing the watermark
System.Drawing.Image Imgwatermark = new Bitmap (workingdirectory + "\" + watermarkname);
int wmwidth = Imgwatermark.width;
int wmheight = Imgwatermark.height;
Create a Bitmap
Bitmap Bmwatermark = new Bitmap (photostream);
Bmwatermark.setresolution (Imgphoto.horizontalresolution, imgphoto.verticalresolution);
Load this Bitmap into a new Graphic Object
Graphics Grwatermark = Graphics.fromimage (Bmwatermark);
ImageAttributes imageattributes = new ImageAttributes ();
This color manipulation was used to change the opacity of the
Watermark. This is doing by applying a 5x5 matrix that contains the
Coordinates for the RGBA. 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.3f, 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);
For this example we'll place the watermark on the upper right
Hand corner of the photograph. Offset down pixels and to the
Left Ten Pixles
int XPOSOFWM = ((phwidth-wmwidth)-10);
int YPOSOFWM = 10;
Grwatermark.drawimage (Imgwatermark,
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,//Watermark Width
Wmheight,//Watermark Height
GraphicsUnit.Pixel,//unit of Measurment
ImageAttributes); ImageAttributes Object
Replace the original photgraphs bitmap with the new bitmap
Imgphoto = Bmwatermark;
Grwatermark.dispose ();