Many websites are copyrighted by their own picture, and they need to be uploaded with copyright symbols, this C # Class In order to deal with such problems. This is an expansion that is written yesterday, adding a text C # process, in addition to adding text on the picture, you can specify the seal in the form of the picture.
The Stamper function is used to add a seal to the image, and Save can save the picture to the specified file or in IO stream.
Using system; using system.drawing; using system.drawing.drawing2d; using system.drawing.image;
Namespace mysite {///
{Public enum position: int {Topleft = 1, TOPRIGHT = 2, BottomleaseFt = 3, Bottomright = 4, Center = 5}
int _margin = 3; private Position _stampPos = Position.TopLeft; private string _originImageFile = "", _stampImageFile = ""; private Bitmap _bmOriginImage, _bmStampImage; private string _stampText = ""; private bool _textStampMode = false; private Font _textFont = new Font ("Arial, Song", 10); Private Color_TextColor = Color.White; private bool_dispose = false
public StamperImage () {_dispose = true;} public StamperImage (string sOriginImageFile, string sStampImageFile) {_originImageFile = sOriginImageFile; _stampImageFile = sStampImageFile; try {_bmOriginImage = new Bitmap (_originImageFile); _bmStampImage = new Bitmap (_stampImageFile);} catch (Exception e) {throw e;}} public StamperImage (Bitmap sOrginImage, Bitmap sStampImage) {_bmOriginImage = sOrginImage; _bmStampImage = sStampImage;} public StamperImage (string sOriginImageFile, string sStampText, Font sStampTextFont, Color sStampTextColor) {_originImageFile = sOriginImageFile; try {_bmOriginImage = new Bitmap (_originImageFile);} catch (Exception e) {throw e;} _textStampMode = true; _stampText = sStampText; _textFont = sStampTextFont; _textColor = sStampTextColor;} public StamperImage (string sOriginImageFile, string sStampText, Font sStampTextFont) {_originImageFile = Soriginimagefile; try {_bmoriginim age = new Bitmap (_originImageFile);} catch (Exception e) {throw e;} _textStampMode = true; _stampText = sStampText; _textFont = sStampTextFont;} public StamperImage (string sOriginImageFile, string sStampText, Color sStampTextColor) {_originImageFile = sOriginImageFile; try {_BMORIGINIMAGE = New bitmap (_ORIGINIMAGEFILE);} catch (exception e) {throw e;} _textstampmode = true; _stamptext = sstamptext; _TextColor = sstamptextColor;}
private void Dispose (bool disposing) {if (! _ dispose) {if (disposing) {if (! _bmOriginImage = null) _bmOriginImage.Dispose (); if (_bmStampImage = null!) _bmStampImage.Dispose (); _dispose = true;} }
Public void dispose () {dispose (true); gc.suppressFinalize (this);} ///
case Position.BottomRight: _stampPoint = new Point (_iOImageWith - _margin - _iSImageWith, _iOImageHeight - _iSImageHeight - _margin); break; case Position.Center:_stampPoint = new Point (_iOImageWith / 2 - _iSImageWith / 2, _iOImageHeight / 2 - _iSImageHeight / 2 ); break; default: _stampPoint = new Point (_margin, _margin); break;} _graSettingImage.DrawImage (_bmStampImage, _stampPoint);} _graSettingImage.Dispose ();} catch (Exception e) {throw e;}} public void Save (String_TargetImageFile) {_bmoriginimage.save (_targetImagefile);} public void save (system.io.stream _stream) {_bmoriginimage.save (_Stream, Imageformat.jpeg);}
///
}}} ///
Below is an example of the use of an ASP.NET page:
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.Web.ui.htmlcontrols;
Namespace MySite {///
IF (_stamper == null) _stamper = ""; if (_stamptext == "|| _stamptext == null) _stamptext =" Hello, World! "; if (_stamppos ==" || _stamppos == null) _stamppos = "1"; if (_stamper.ToLower () = "on"!) {_stamperImage = new StamperImage (_sampleImageFile, _stampText, Color.White);} else {_stamperImage = new StamperImage (_sampleImageFile, _stampImageFile);} _stamperImage.StampPos = (StamperImage.Position) Convert.Toint16 (_stamppos); _StamperImage.Stamper (); _StamperImage.Save (response.outputstream); _stamperimage.dispose ();}
#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///