EDN Admin
Well-known member
Any help would be nice.
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // Thumbnail-size image
Byte[] byteBLOBData = <span style="color:Blue; new Byte[0]; <span style="color:Green; // Get image from database in byte type
byteBLOBData = (<span style="color:Blue; byte[])dReader[<span style="color:#A31515; "p_Image"];
ImageExtension = dReader[<span style="color:#A31515; "p_Type"].ToString(); <span style="color:Green; // get type of image
MemoryStream stmBLOBData = <span style="color:Blue; new MemoryStream(byteBLOBData);
stmBLOBData.Write(byteBLOBData, 0, byteBLOBData.Length); <span style="color:Green; // Load image into stream
<span style="color:Green; // Grab initial image
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(stmBLOBData, <span style="color:Blue; false, <span style="color:Blue; false);
<span style="color:Gray; ///<span style="color:Green; /////////////////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; // resize initial image
System.Drawing.Image imgPhoto = ImageHandler.ImageCrop(returnImage, 100, 160, ImageHandler.AnchorPosition.Bottom);
<span style="color:Blue; int phWidth = 100;
<span style="color:Blue; int phHeight = 160;
<span style="color:Green; //create a Bitmap the Size of the original photograph
Bitmap bmPhoto = <span style="color:Blue; new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); <span style="color:Green; // new resized bmp
<span style="color:Gray; ///<span style="color:Green; /////////////////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; //load the Bitmap into a Graphics object
Graphics grPhoto = Graphics.FromImage(bmPhoto);
<span style="color:Green; //create a image object containing the watermark
System.Drawing.Image imgWatermark = <span style="color:Blue; null;
<span style="color:Blue; int wmWidth = 0;
<span style="color:Blue; int wmHeight = 0;
imgWatermark = <span style="color:Blue; new Bitmap(System.Web.HttpContext.Current.Server.MapPath(<span style="color:#A31515; "~/Images/Watermark/watermark.jpg"));
wmWidth = imgWatermark.Width;
wmHeight = imgWatermark.Height;
<span style="color:Gray; ///<span style="color:Green; //////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; //------------------------------------------------------------
<span style="color:Green; //Step #2 - Insert Watermark image
<span style="color:Green; //------------------------------------------------------------
Bitmap bmWatermark = <span style="color:Blue; null;
Graphics grWatermark = <span style="color:Blue; null;
<span style="color:Green; //Create a Bitmap based on the previously modified photograph Bitmap
bmWatermark = <span style="color:Blue; new Bitmap(bmPhoto);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
<span style="color:Green; //Load this Bitmap into a new Graphic Object
grWatermark = Graphics.FromImage(bmWatermark);
<span style="color:Green; //To achieve a transulcent watermark we will apply (2) color
<span style="color:Green; //manipulations by defineing a ImageAttributes object and
<span style="color:Green; //seting (2) of its properties.
<span style="color:Green; //System.ImageAttributes imageAttributes = new ImageAttributes();
<span style="color:Green; //The first step in manipulating the watermark image is to replace
<span style="color:Green; //the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)
<span style="color:Green; //to do this we will use a Colormap and use this to define a RemapTable
<span style="color:Green; //ColorMap colorMap = new ColorMap();
<span style="color:Green; //My watermark was defined with a background of 100% Green this will
<span style="color:Green; //be the color we search for and replace with transparency
<span style="color:Green; //colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
<span style="color:Green; //colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
<span style="color:Green; //ColorMap[] remapTable = { colorMap };
<span style="color:Green; //imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
<span style="color:Green; //The second color manipulation is used to change the opacity of the
<span style="color:Green; //watermark. This is done by applying a 5x5 matrix that contains the
<span style="color:Green; //coordinates for the RGBA space. By setting the 3rd row and 3rd column
<span style="color:Green; //to 0.3f we achive a level of opacity
<span style="color:Green; //float[][] colorMatrixElements = {
<span style="color:Green; // new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};
<span style="color:Green; //ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
<span style="color:Green; //imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
<span style="color:Green; // ColorAdjustType.Bitmap);
<span style="color:Green; //For this example we will place the watermark in the upper right
<span style="color:Green; //hand corner of the photograph. offset down 10 pixels and to the
<span style="color:Green; //left 10 pixles
<span style="color:Green; //int xPosOfWm = ((phWidth - wmWidth) - 10);
<span style="color:Green; //int yPosOfWm = 10;
<span style="color:Green; //grWatermark.DrawImage(imgWatermark,
<span style="color:Green; // new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), //Set the detination Position
<span style="color:Green; // 0, // x-coordinate of the portion of the source image to draw.
<span style="color:Green; // 0, // y-coordinate of the portion of the source image to draw.
<span style="color:Green; // wmWidth, // Watermark Width
<span style="color:Green; // wmHeight, // Watermark Height
<span style="color:Green; // GraphicsUnit.Pixel, // Unit of measurment
<span style="color:Green; // imageAttributes); //ImageAttributes Object
<span style="color:Green; //Replace the original photgraphs bitmap with the new Bitmap
<span style="color:Green; //imgPhoto = bmWatermark;
<span style="color:Green; //grWatermark.Dispose();
<span style="color:Gray; ///<span style="color:Green; ////////////////////////////////////////////////////////////////////////////////////////////////////////
context.Response.ContentType = <span style="color:#A31515; "image/jpeg";
context.Response.Clear();
<span style="color:Green; // Buffer response so that page is sent
<span style="color:Green; // after processing is complete.
context.Response.BufferOutput = <span style="color:Blue; true;
imgPhoto.Save(context.Response.OutputStream, ImageFormat.Jpeg);
grPhoto.Dispose();
imgPhoto.Dispose();
imgWatermark.Dispose();
returnImage.Dispose();
<span style="color:Green; // Send the output to the client.
context.Response.Flush();
[/code]
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // Thumbnail-size image
Byte[] byteBLOBData = <span style="color:Blue; new Byte[0]; <span style="color:Green; // Get image from database in byte type
byteBLOBData = (<span style="color:Blue; byte[])dReader[<span style="color:#A31515; "p_Image"];
ImageExtension = dReader[<span style="color:#A31515; "p_Type"].ToString(); <span style="color:Green; // get type of image
MemoryStream stmBLOBData = <span style="color:Blue; new MemoryStream(byteBLOBData);
stmBLOBData.Write(byteBLOBData, 0, byteBLOBData.Length); <span style="color:Green; // Load image into stream
<span style="color:Green; // Grab initial image
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(stmBLOBData, <span style="color:Blue; false, <span style="color:Blue; false);
<span style="color:Gray; ///<span style="color:Green; /////////////////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; // resize initial image
System.Drawing.Image imgPhoto = ImageHandler.ImageCrop(returnImage, 100, 160, ImageHandler.AnchorPosition.Bottom);
<span style="color:Blue; int phWidth = 100;
<span style="color:Blue; int phHeight = 160;
<span style="color:Green; //create a Bitmap the Size of the original photograph
Bitmap bmPhoto = <span style="color:Blue; new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); <span style="color:Green; // new resized bmp
<span style="color:Gray; ///<span style="color:Green; /////////////////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; //load the Bitmap into a Graphics object
Graphics grPhoto = Graphics.FromImage(bmPhoto);
<span style="color:Green; //create a image object containing the watermark
System.Drawing.Image imgWatermark = <span style="color:Blue; null;
<span style="color:Blue; int wmWidth = 0;
<span style="color:Blue; int wmHeight = 0;
imgWatermark = <span style="color:Blue; new Bitmap(System.Web.HttpContext.Current.Server.MapPath(<span style="color:#A31515; "~/Images/Watermark/watermark.jpg"));
wmWidth = imgWatermark.Width;
wmHeight = imgWatermark.Height;
<span style="color:Gray; ///<span style="color:Green; //////////////////////////////////////////////////////////////////////////////////////////
<span style="color:Green; //------------------------------------------------------------
<span style="color:Green; //Step #2 - Insert Watermark image
<span style="color:Green; //------------------------------------------------------------
Bitmap bmWatermark = <span style="color:Blue; null;
Graphics grWatermark = <span style="color:Blue; null;
<span style="color:Green; //Create a Bitmap based on the previously modified photograph Bitmap
bmWatermark = <span style="color:Blue; new Bitmap(bmPhoto);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
<span style="color:Green; //Load this Bitmap into a new Graphic Object
grWatermark = Graphics.FromImage(bmWatermark);
<span style="color:Green; //To achieve a transulcent watermark we will apply (2) color
<span style="color:Green; //manipulations by defineing a ImageAttributes object and
<span style="color:Green; //seting (2) of its properties.
<span style="color:Green; //System.ImageAttributes imageAttributes = new ImageAttributes();
<span style="color:Green; //The first step in manipulating the watermark image is to replace
<span style="color:Green; //the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0)
<span style="color:Green; //to do this we will use a Colormap and use this to define a RemapTable
<span style="color:Green; //ColorMap colorMap = new ColorMap();
<span style="color:Green; //My watermark was defined with a background of 100% Green this will
<span style="color:Green; //be the color we search for and replace with transparency
<span style="color:Green; //colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
<span style="color:Green; //colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
<span style="color:Green; //ColorMap[] remapTable = { colorMap };
<span style="color:Green; //imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
<span style="color:Green; //The second color manipulation is used to change the opacity of the
<span style="color:Green; //watermark. This is done by applying a 5x5 matrix that contains the
<span style="color:Green; //coordinates for the RGBA space. By setting the 3rd row and 3rd column
<span style="color:Green; //to 0.3f we achive a level of opacity
<span style="color:Green; //float[][] colorMatrixElements = {
<span style="color:Green; // new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
<span style="color:Green; // new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};
<span style="color:Green; //ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
<span style="color:Green; //imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
<span style="color:Green; // ColorAdjustType.Bitmap);
<span style="color:Green; //For this example we will place the watermark in the upper right
<span style="color:Green; //hand corner of the photograph. offset down 10 pixels and to the
<span style="color:Green; //left 10 pixles
<span style="color:Green; //int xPosOfWm = ((phWidth - wmWidth) - 10);
<span style="color:Green; //int yPosOfWm = 10;
<span style="color:Green; //grWatermark.DrawImage(imgWatermark,
<span style="color:Green; // new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), //Set the detination Position
<span style="color:Green; // 0, // x-coordinate of the portion of the source image to draw.
<span style="color:Green; // 0, // y-coordinate of the portion of the source image to draw.
<span style="color:Green; // wmWidth, // Watermark Width
<span style="color:Green; // wmHeight, // Watermark Height
<span style="color:Green; // GraphicsUnit.Pixel, // Unit of measurment
<span style="color:Green; // imageAttributes); //ImageAttributes Object
<span style="color:Green; //Replace the original photgraphs bitmap with the new Bitmap
<span style="color:Green; //imgPhoto = bmWatermark;
<span style="color:Green; //grWatermark.Dispose();
<span style="color:Gray; ///<span style="color:Green; ////////////////////////////////////////////////////////////////////////////////////////////////////////
context.Response.ContentType = <span style="color:#A31515; "image/jpeg";
context.Response.Clear();
<span style="color:Green; // Buffer response so that page is sent
<span style="color:Green; // after processing is complete.
context.Response.BufferOutput = <span style="color:Blue; true;
imgPhoto.Save(context.Response.OutputStream, ImageFormat.Jpeg);
grPhoto.Dispose();
imgPhoto.Dispose();
imgWatermark.Dispose();
returnImage.Dispose();
<span style="color:Green; // Send the output to the client.
context.Response.Flush();
[/code]
View the full article