Graphics
of
DrawImage
Method, a variety of prototypes are defined, and designated
Image
Object. With this method, you can draw a watermark image on the picture object. Combine
FreetextBox
Convenient image upload features, you can implement a news system that is suitable for more pictures. the following
Watermark
The method belongs to the parameters of the file stream, the original picture name, the watermark picture name, the picture save path, etc., the correspondence, the correspondence, the code should not have much 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 Photography 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 is buy to change the opacity of the
// Watermark. 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.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 Will Place THE WATERMARK IN THE UPER RIGHT
// Hand Corner of the photography. Offset Down 10 Pixels and to The
// Left 10 Pixles
INT XPOSOFWM = ((Phwidth - Wmwidth) -10);
INT YPOSOFWM = 10;
Grwatermark.drawImage (Imgwatermark,
New Rectangle (xposofwm, yposofwm, wmwidth, wmheight), // set the debinament 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 Measurement
ImageAttributes; // ImageAttributes Object
// Replace the Original Photgraphs Bitmap with the New Bitmap
Imgphoto = bmwatermark;
Grwatermark.dispose ();
// Save New Image to File System.
Imgphoto.save (WorkingDirectory "//" PhotofinalName, ImageFormat.jpeg);
IMGphoto.dispose ();
Imgwatermark.dispose ();
Photostream.close ();
}
-------------------------------------------------- ------------------
The image upload of FTB mainly uses the HTMLINPUTFILE control, corresponding to the properties of the HTMLInputFile class, which contains the SaveAs method to save the image. Of course, we don't want to read it again after the picture is saved. If you check the MSDN, you find that the postedfile property returns an instance of the HTTPPostedFile class, and httppostedfile has an InputStream object, and the file uploaded by the HTMLINPUTFILE control The upload file stream is obtained by the Stream object, and the final function is implemented as the parameters of Watermake. So finally, as long as the FTB.ImageGallery.aspx file is noted in the FTB UPLOADFILE.POSTEDFILE.SAVEAS ' , "UploadPics"); of course, put the Watermake method in the code.