using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
public class FotoFiligrana
{
private string _pathFoto;
public string PathFoto
{
get { return _pathFoto; }
set { _pathFoto = value; }
}
private string _testo;
public string Testo
{
get { return _testo;}
set { _testo = value; }
}
public FotoFiligrana(string par_PathFoto)
{
_pathFoto = par_PathFoto;
}
public void Applicafiligrana()
{
//testo della filigrana
string testoFiligrana =this._testo;
//Carico l' immagine
Bitmap bitMapImage = new
System.Drawing.Bitmap(
HttpContext.Current.Server.MapPath(this._pathFoto));
Graphics graphicImage = Graphics.FromImage(bitMapImage);
//Uso antialias che la rende piu' carina ...
graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
SolidBrush oBrush = new SolidBrush(Color.Black);
Font oFont = new Font("Arial", 8, FontStyle.Bold);
graphicImage.DrawString(
testoFiligrana,
oFont,
oBrush, 10, bitMapImage.Height - 30);
graphicImage.DrawString(
testoFiligrana,
oFont,
oBrush, 10, 10);
//Salvo la nuova immagine nel path selezionato (small image)
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
ImageCodecInfo myImageCodecInfo;
// Get an ImageCodecInfo object that represents the JPEG codec.
myImageCodecInfo = GetEncoderInfo("image/jpeg");
// for the Quality parameter category.
myEncoder = Encoder.Quality;
// EncoderParameter object in the array.
myEncoderParameters = new EncoderParameters(1);
// Save the bitmap as a JPEG file with quality level 100.
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
Bitmap bm = new Bitmap(bitMapImage);
graphicImage.Dispose();
bitMapImage.Dispose();
bm.Save(HttpContext.Current.Server.MapPath(this._pathFoto), myImageCodecInfo, myEncoderParameters);
}
public static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
}


0 commenti
Posta un commento