Add image to FreetextBox1.6.5 plus watermark

xiaoxiao2021-03-06  32

The DrawImage method of Graphics defines a variety of prototypes that can be drawn to the specified image object in the development location. With this method, you can draw a watermark image on the picture object. Combined with the FreetextBox easy image upload function, you can implement a news system that is suitable for more pictures. The following Watermark method belongs to the file stream, the original picture name, the watermark picture name, the picture save path, etc., the correspondence, the correspondence is not 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.

转载请注明原文地址:https://www.9cbs.com/read-62682.html

New Post(0)