public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } ColorMatrix grayscaleMatrix = new ColorMatrix(new[] { new[] {.3f, .3f, .3f, 0, 0}, new[] {.59f, .59f, .59f, 0, 0}, new[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); using (ImageAttributes ia = new ImageAttributes()) { ia.SetColorMatrix(grayscaleMatrix); graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); } graphics.Restore(state); }
/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <param name="image">The current image to process</param> /// <param name="newImage">The new Image to return</param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image TransformImage(ImageFactory factory, Image image, Image newImage) { using (Graphics graphics = Graphics.FromImage(newImage)) { using (ImageAttributes attributes = new ImageAttributes()) { attributes.SetColorMatrix(this.Matrix); Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height); graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); } } // Add a vignette to finish the effect. factory.Update(newImage); Vignette vignette = new Vignette(); newImage = (Bitmap)vignette.ProcessImage(factory); // Reassign the image. image.Dispose(); image = newImage; return image; }
//this function change the brightness of the image public static Bitmap AdjustBrightness(Bitmap Image, int Value) { System.Drawing.Bitmap TempBitmap = Image; float FinalValue = (float)Value / 255.0f; //calculate the scaling value System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height); System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap); float[][] FloatColorMatrix = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { FinalValue, FinalValue, FinalValue, 1, 1 } }; //create the matrix for brightness calculation System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(FloatColorMatrix); System.Drawing.Imaging.ImageAttributes Attributes = new System.Drawing.Imaging.ImageAttributes(); Attributes.SetColorMatrix(NewColorMatrix); //redraw the image NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes); Attributes.Dispose(); NewGraphics.Dispose(); return(NewBitmap); }
public static Bitmap Grayscale(Image b, float brightnessAdjust = 1) { Bitmap bDest = new Bitmap(b.Width, b.Height, b.PixelFormat); // Create the ImageAttributes object and apply the ColorMatrix ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes(); ColorMatrix grayscaleMatrix = new ColorMatrix(new float[][] { new float[] { 0.299f, 0.299f, 0.299f, 0, 0 }, new float[] { 0.587f, 0.587f, 0.587f, 0, 0 }, new float[] { 0.114f, 0.114f, 0.114f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); attributes.SetColorMatrix(grayscaleMatrix); // Use a new Graphics object from the new image. using (Graphics g = Graphics.FromImage(bDest)) { // Draw the original image using the ImageAttributes created above. g.DrawImage(b, new Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, attributes); } if (brightnessAdjust != 1.0f) { return(Brightness(bDest, brightnessAdjust)); } return(bDest); }
/// <summary> /// Initialises a new instance of <a cref="Salamander.Windows.Forms.CollapsiblePanel">CollapsiblePanel</a>. /// </summary> public CollapsiblePanel() : base() { this.components = new System.ComponentModel.Container(); InitializeComponent(); // Set the background colour to ControlLightLight this.BackColor = Color.AliceBlue; // Store the current panelHeight this.panelHeight = this.Height; // Setup the ColorMatrix and ImageAttributes for grayscale images. this.grayMatrix = new ColorMatrix(); this.grayMatrix.Matrix00 = 1 / 3f; this.grayMatrix.Matrix01 = 1 / 3f; this.grayMatrix.Matrix02 = 1 / 3f; this.grayMatrix.Matrix10 = 1 / 3f; this.grayMatrix.Matrix11 = 1 / 3f; this.grayMatrix.Matrix12 = 1 / 3f; this.grayMatrix.Matrix20 = 1 / 3f; this.grayMatrix.Matrix21 = 1 / 3f; this.grayMatrix.Matrix22 = 1 / 3f; this.grayAttributes = new ImageAttributes(); this.grayAttributes.SetColorMatrix(this.grayMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); }
public static Bitmap Inversion(Image b) { Bitmap bDest = new Bitmap(b.Width, b.Height, b.PixelFormat); // Create the ImageAttributes object and apply the ColorMatrix ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes(); ColorMatrix inversionMatrix = new ColorMatrix(new float[][] { new float[] { -1, 0, 0, 0, 0 }, new float[] { 0, -1, 0, 0, 0 }, new float[] { 0, 0, -1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { .99f, .99f, .99f, 0, 1 } }); attributes.SetColorMatrix(inversionMatrix); // Use a new Graphics object from the new image. using (Graphics g = Graphics.FromImage(bDest)) { // Draw the original image using the ImageAttributes created above. g.DrawImage(b, new Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, attributes); } return(bDest); }
public static Bitmap Brightness(Image b, float brightness) { Bitmap bDest = new Bitmap(b.Width, b.Height, b.PixelFormat); float adjustedBrightness = brightness - 1.0f; // Create the ImageAttributes object and apply the ColorMatrix ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes(); ColorMatrix brightnessMatrix = new ColorMatrix(new float[][] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 0, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { brightness, brightness, brightness, 0, 1 } }); attributes.SetColorMatrix(brightnessMatrix); // Use a new Graphics object from the new image. using (Graphics g = Graphics.FromImage(bDest)) { // Draw the original image using the ImageAttributes created above. g.DrawImage(b, new Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, attributes); } return(bDest); }
public static Bitmap GetRowImage(GridView view, int rowHandle) { GridViewInfo gvi = view.GetViewInfo() as GridViewInfo; GridDataRowInfo ri = gvi.RowsInfo.OfType <GridDataRowInfo>().Where(r => r.RowHandle == rowHandle).FirstOrDefault(); Bitmap rowBmp = null; if (ri != null) { Bitmap gridBmp = new Bitmap(view.GridControl.Width, view.GridControl.Height); view.GridControl.DrawToBitmap(gridBmp, new Rectangle(0, 0, view.GridControl.Width, view.GridControl.Height)); float[][] matrixItems = new float[][] { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 0.7F, 0 }, new float[] { 0, 0, 0, 0, 1 } }; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes(); attr.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); rowBmp = new Bitmap(ri.DataBounds.Width, ri.DataBounds.Height); Graphics gr = Graphics.FromImage(rowBmp); Rectangle imageBounds = new Rectangle(Point.Empty, ri.DataBounds.Size); gr.DrawImage(gridBmp, imageBounds, ri.DataBounds.X, ri.DataBounds.Y, ri.DataBounds.Width, ri.DataBounds.Height, GraphicsUnit.Pixel, attr); } return(rowBmp); }
private void pictureBox11_Click(object sender, EventArgs e) { undo.Push(pictureBox2.Image); imi1 = pictureBox2.Image; ImUndo = imi1; Bitmap originalImage = (Bitmap)pictureBox2.Image; Bitmap adjustedImage = (Bitmap)pictureBox2.Image; float brightness = 1.0f; // no change in brightness float contrast = Convert.ToSingle(numericUpDown1.Value); // twice the contrast float gamma = 1.0f; // no change in gamma float adjustedBrightness = brightness - 1.0f; // create matrix that will brighten and contrast the image float[][] ptsArray = { new float[] { contrast, 0, 0, 0, 0 }, // scale red new float[] { 0, contrast, 0, 0, 0 }, // scale green new float[] { 0, 0, contrast, 0, 0 }, // scale blue new float[] { 0, 0, 0, 1.0f, 0 }, // don't scale alpha new float[] { adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1 } }; System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); imageAttributes.ClearColorMatrix(); imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap); imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap); Graphics g = Graphics.FromImage(adjustedImage); g.DrawImage(originalImage, new Rectangle(0, 0, adjustedImage.Width, adjustedImage.Height) , 0, 0, originalImage.Width, originalImage.Height, GraphicsUnit.Pixel, imageAttributes); pictureBox2.Image = adjustedImage; sandi = adjustedImage; }
/// <summary> /// Processes the image. /// </summary> /// <param name="source">The current image to process</param> /// <param name="destination">The new Image to return</param> /// <returns> /// The processed <see cref="System.Drawing.Bitmap"/>. /// </returns> public override Bitmap TransformImage(Image source, Image destination) { using (Graphics graphics = Graphics.FromImage(destination)) { using (ImageAttributes attributes = new ImageAttributes()) { attributes.SetColorMatrix(this.Matrix); Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height); graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes); } } // Fade the contrast destination = Adjustments.Contrast(destination, -25); // Add a glow to the image. destination = Effects.Glow(destination, Color.FromArgb(70, 255, 153, 102)); // Add a vignette to finish the effect. destination = Effects.Vignette(destination, Color.FromArgb(220, 102, 34, 0)); return (Bitmap)destination; }
/* * public static Image CreateDisabledImage(Image srcImage) * { * if (srcImage == null) return null; * return ToolStripRenderer.CreateDisabledImage(srcImage); * } */ public static Image CreateBlackWhite(Image srcImage) { if (srcImage == null) { return(null); } var newImage = (Image)srcImage.Clone(); using (var gr = Graphics.FromImage(newImage)) // SourceImage is a Bitmap object { var gray_matrix = new[] { new float[] { 0.299f, 0.299f, 0.299f, 0, 0 }, new float[] { 0.587f, 0.587f, 0.587f, 0, 0 }, new float[] { 0.114f, 0.114f, 0.114f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }; var ia = new System.Drawing.Imaging.ImageAttributes(); ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix)); ia.SetThreshold(0.8f); // Change this threshold as needed var rc = new Rectangle(0, 0, newImage.Width, newImage.Height); gr.DrawImage(newImage, rc, 0, 0, newImage.Width, newImage.Height, GraphicsUnit.Pixel, ia); } return(newImage); }
// Obraz w skali szarości; internal void grayScale(MyBitmap myBitmap) { myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone(); //Srednia skladowych // Wykorzystanie modelu YUV const float rMod = 0.333f; //rMod = 0.299f; const float gMod = 0.333f; //gMod = 0.587f; const float bMod = 0.333f; //bMod = 0.114f; Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap); ColorMatrix colorMatrix = new ColorMatrix(new[] { new[] {rMod, rMod, rMod, 0, 1}, new[] {gMod, gMod, gMod, 0, 1}, new[] {bMod, bMod, bMod, 0, 1}, new[] {0.0f, 0.0f, 0.0f, 1, 1}, new[] {0.0f, 0.0f, 0.0f, 0, 1} }); ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(colorMatrix); int x = myBitmap.BitmapInfo.SizeX; int y = myBitmap.BitmapInfo.SizeY; g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes); //myBitmap.updateArrays(); g.Dispose(); }
public static Bitmap GetGhostBitmap(string name) { float[][] newColorMatrix = new float[5][]; float[] numArray2 = new float[5]; numArray2[0] = 1f; newColorMatrix[0] = numArray2; numArray2 = new float[5]; numArray2[1] = 1f; newColorMatrix[1] = numArray2; numArray2 = new float[5]; numArray2[2] = 1f; newColorMatrix[2] = numArray2; numArray2 = new float[5]; numArray2[3] = 0.5f; newColorMatrix[3] = numArray2; numArray2 = new float[5]; numArray2[4] = 1f; newColorMatrix[4] = numArray2; ColorMatrix matrix = new ColorMatrix(newColorMatrix); ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Bitmap image = GetBitmap(name); Bitmap bitmap2 = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bitmap2)) { graphics.FillRectangle(SystemBrushes.Window, new Rectangle(0, 0, image.Width, image.Height)); graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr); } return bitmap2; }
/// <summary> /// Set brightness for the image /// </summary> /// <param name="image">input bitmap</param> /// <param name="value">value from -255 to 255</param> /// <returns></returns> public static Bitmap SetBrightness(Bitmap image, int value) { var tempBitmap = image; var finalValue = value / 255.0f; var newBitmap = new Bitmap(tempBitmap.Width, tempBitmap.Height); var newGraphics = Graphics.FromImage(newBitmap); float[][] floatColorMatrix = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new[] { finalValue, finalValue, finalValue, 1, 1 } }; var newColorMatrix = new System.Drawing.Imaging.ColorMatrix(floatColorMatrix); var attributes = new System.Drawing.Imaging.ImageAttributes(); attributes.SetColorMatrix(newColorMatrix); newGraphics.DrawImage(tempBitmap, new System.Drawing.Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), 0, 0, tempBitmap.Width, tempBitmap.Height, GraphicsUnit.Pixel, attributes); attributes.Dispose(); newGraphics.Dispose(); return(newBitmap); }
// Callback from VolumeDetector public void AudioChanged(DeviceInfo info) { // Windows7 sometimes triggers callback when volume hasn't changed. if (lastInfo != null) { if (info.Muted == lastInfo.Muted && info.Volume == lastInfo.Volume ) return; } lastInfo = info; try { this.Opacity = settings.Opacity + _Opacity; if (this.Visible == false) this.Visible = true; // throw in preview // Manually draw the image to get the transparency string image = ResolveImage(info, settings, BasePath); System.Drawing.Image actualImage = System.Drawing.Image.FromFile(image); ImageAttributes attr = new ImageAttributes(); Rectangle dstRect = new Rectangle(0, 0, actualImage.Width, actualImage.Height); CreateGraphics().DrawImage(actualImage, dstRect, 0, 0, actualImage.Width, actualImage.Height, GraphicsUnit.Pixel, attr); System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(WaitAndHide)); lastMove = System.DateTime.Now; t.Start(); } catch (ObjectDisposedException) { // In preview we recieved a callback from an item that we cannot // access return; } }
public void PrintScreenThreshold() { //Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); //System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(printscreen as Image); //graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size); Bitmap printscreen = new Bitmap(@"test\cap2.jpg"); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(printscreen)) { var gray_matrix = new float[][] { new float[] { 0.299f, 0.299f, 0.299f, 0, 0 }, new float[] { 0.587f, 0.587f, 0.587f, 0, 0 }, new float[] { 0.114f, 0.114f, 0.114f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }; var ia = new System.Drawing.Imaging.ImageAttributes(); ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix)); ia.SetThreshold((float)0.50); // Change this threshold as needed (old .33) var rc = new Rectangle(0, 0, printscreen.Width, printscreen.Height); gr.DrawImage(printscreen, rc, 0, 0, printscreen.Width, printscreen.Height, GraphicsUnit.Pixel, ia); printscreen.Save("rewards.jpg", ImageFormat.Jpeg); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics G = e.Graphics; //利用位图作为纹理创建纹理画刷 TextureBrush textureBrush1 = new TextureBrush(Properties.Resources.test); G.FillRectangle(textureBrush1, 40, 0, 40, 120); G.FillRectangle(textureBrush1, 0, 40, 120, 40); //利用位置的指定区域作为纹理创建纹理画刷 TextureBrush textureBrush2 = new TextureBrush(Properties.Resources.test, new Rectangle(10, 10, 28, 28)); G.FillRectangle(textureBrush2, 180, 0, 40, 120); G.FillRectangle(textureBrush2, 140, 40, 120, 40); TextureBrush textureBrush3 = new TextureBrush(Properties.Resources.test, new Rectangle(10, 10, 28, 28)); textureBrush3.WrapMode = WrapMode.TileFlipXY; //设置纹理图像的渐变方式 G.FillRectangle(textureBrush3, 30, 140, 60, 120); G.FillRectangle(textureBrush3, 0, 170, 120, 60); float[][] newColorMatrix = new float[][]{ //颜色变换矩形 new float[]{0.2f,0,0,0,0}, //红色分量 new float[]{0,0.6f,0,0,0}, //绿色分量 new float[]{0,0,0.2f,0,0}, //蓝色分量 new float[]{0,0,0,0.5f,0}, //透明度分量 new float[]{0,0,0,0,1}}; //始终为1 ColorMatrix colorMatrix = new ColorMatrix(newColorMatrix); ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); TextureBrush textureBrush4 = new TextureBrush(Properties.Resources.test, new Rectangle(0, 0, 48, 48), imageAttributes); textureBrush4.WrapMode = WrapMode.TileFlipXY; G.FillRectangle(textureBrush4, 170, 140, 60, 120); G.FillRectangle(textureBrush4, 140, 170, 120, 60); textureBrush1.Dispose(); //释放画刷 textureBrush2.Dispose(); //释放画刷 textureBrush3.Dispose(); //释放画刷 textureBrush4.Dispose(); //释放画刷 }
/// <summary> /// 指定された画像からネガティブイメージを作成する /// </summary> /// <param name="img">基の画像</param> /// <returns>作成されたネガティブイメージ</returns> public static Image CreateNegativeImage(Image img) { //ネガティブイメージの描画先となるImageオブジェクトを作成 Bitmap negaImg = new Bitmap(img.Width, img.Height); //negaImgのGraphicsオブジェクトを取得 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(negaImg); //ColorMatrixオブジェクトの作成 System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(); //ColorMatrixの行列の値を変更して、色が反転されるようにする cm.Matrix00 = -1; cm.Matrix11 = -1; cm.Matrix22 = -1; cm.Matrix33 = 1; cm.Matrix40 = cm.Matrix41 = cm.Matrix42 = cm.Matrix44 = 1; //ImageAttributesオブジェクトの作成 System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); //ColorMatrixを設定する ia.SetColorMatrix(cm); //ImageAttributesを使用して色が反転した画像を描画 g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia); //リソースを解放する g.Dispose(); return(negaImg); }
private Bitmap MakeGrayscaleWithColorMatrix(Bitmap original) { //create a blank bitmap the same size as original Bitmap newBitmap = new Bitmap(original.Width, original.Height); //get a graphics object from the new image Graphics g = Graphics.FromImage(newBitmap); //create the grayscale ColorMatrix ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new float[] {.3f, .3f, .3f, 0, 0}, new float[] {.59f, .59f, .59f, 0, 0}, new float[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); //create some image attributes ImageAttributes attributes = new ImageAttributes(); //set the color matrix attribute attributes.SetColorMatrix(colorMatrix); //draw the original image on the new image //using the grayscale color matrix g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes); //dispose the Graphics object g.Dispose(); return newBitmap; }
private void ColorFilter(float[][] values, PictureBox control) { this.Text = "Color - Processing..."; this.Cursor = System.Windows.Forms.Cursors.WaitCursor; if (control.Image == null) { control.Image = new Bitmap(source); } this.Cursor = System.Windows.Forms.Cursors.WaitCursor; Bitmap local_source = new Bitmap(control.Image); System.Drawing.Imaging.ColorMatrix filterMatrix = new System.Drawing.Imaging.ColorMatrix(values); System.Drawing.Imaging.ImageAttributes IA = new System.Drawing.Imaging.ImageAttributes(); IA.SetColorMatrix(filterMatrix); Bitmap filter = new Bitmap(local_source); using (Graphics G = Graphics.FromImage(filter)) { G.DrawImage(local_source, new Rectangle(0, 0, filter.Width, filter.Height), 0, 0, filter.Width, filter.Height, GraphicsUnit.Pixel, IA); } control.Image = filter; this.Text = "Color - Ready !"; this.Cursor = System.Windows.Forms.Cursors.Arrow; }
public static Image CreateGrayscaleImage(Image img) { var newImg = new Bitmap(img.Width, img.Height); var g = Graphics.FromImage(newImg); var cm = new System.Drawing.Imaging.ColorMatrix( new float[][] { new float[] { 0.3086f, 0.3086f, 0.3086f, 0, 0 }, new float[] { 0.6094f, 0.6094f, 0.6094f, 0, 0 }, new float[] { 0.0820f, 0.0820f, 0.0820f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); var ia = new System.Drawing.Imaging.ImageAttributes(); ia.SetColorMatrix(cm); g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia); g.Dispose(); return(newImg); }
public static Bitmap ResizeBitmap(Bitmap bmp, int width, int height) { if (width == 0 || height == 0) { return(bmp); } Rectangle destRect = new Rectangle(0, 0, width, height); Bitmap destBmp = new Bitmap(width, height); using (Graphics gfx = Graphics.FromImage(destBmp)) { gfx.CompositingMode = CompositingMode.SourceCopy; gfx.CompositingQuality = CompositingQuality.HighQuality; gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new System.Drawing.Imaging.ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.Tile); gfx.DrawImage(bmp, destRect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, wrapMode); } } return(destBmp); }
/// <summary> /// Executes this filter on the input image and returns the result /// </summary> /// <param name="inputImage">input image</param> /// <returns>transformed image</returns> public override Image ExecuteFilter(Image inputImage) { ///Reference from http://www.bobpowell.net/grayscale.htm Bitmap bm = new Bitmap(inputImage.Width, inputImage.Height); Graphics g = Graphics.FromImage(bm); ColorMatrix cm; if (_isBright) { cm = new ColorMatrix(new float[][]{ new float[]{0.5f,0.5f,0.5f,0,0}, new float[]{0.5f,0.5f,0.5f,0,0}, new float[]{0.5f,0.5f,0.5f,0,0}, new float[]{0,0,0,1,0,0}, new float[]{0,0,0,0,1,0}, new float[]{0,0,0,0,0,1}}); } else { //Gilles Khouzams colour corrected grayscale shear cm = new ColorMatrix(new float[][]{ new float[]{0.3f,0.3f,0.3f,0,0}, new float[]{0.59f,0.59f,0.59f,0,0}, new float[]{0.11f,0.11f,0.11f,0,0}, new float[]{0,0,0,1,0,0}, new float[]{0,0,0,0,1,0}, new float[]{0,0,0,0,0,1}}); } ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix(cm); g.DrawImage(inputImage, new Rectangle(0, 0, inputImage.Width, inputImage.Height), 0, 0, inputImage.Width, inputImage.Height, GraphicsUnit.Pixel, ia); g.Dispose(); return bm; }
public ScrollBarThumb(ScrollBarThumbDefaults type) { this._imageAttributes = new ImageAttributes(); this._imageAttributes.ClearColorKey(); this._gripImageAttributes = new ImageAttributes(); this._gripImageAttributes.ClearColorKey(); switch (type) { case ScrollBarThumbDefaults.Normal: this._color = SystemColors.ScrollBar; this._gripColor = SystemColors.ControlText; break; case ScrollBarThumbDefaults.Highlight: this._color = SystemColors.ControlText; this._gripColor = SystemColors.HighlightText; break; } this._borderStyle = ScrollBarBorderStyle.Solid; this._borderColor = SystemColors.ControlText; this._gradientColor = new Resco.Controls.ScrollBar.GradientColor(FillDirection.Horizontal); this._gradientColor.PropertyChanged += new EventHandler(this.GradientColor_PropertyChanged); this._image = null; this._imageLayout = ScrollBarThumbImageLayout.Stretch; this._imageTransparentColor = System.Drawing.Color.Transparent; this._gripStyle = ScrollBarThumbGripStyle.Lines; this._gripImage = null; this._gripImageTransparentColor = System.Drawing.Color.Transparent; this._gripLines = 3; }
/// <summary> /// Resizes and rotates an image, keeping the original aspect ratio. Does not dispose the original /// Image instance. /// </summary> /// <param name="image">Image instance</param> /// <param name="width">desired width</param> /// <param name="height">desired height</param> /// <param name="rotateFlipType">desired RotateFlipType</param> /// <returns>new resized/rotated Image instance</returns> public static System.Drawing.Image Resize(System.Drawing.Image image, int width, int height, RotateFlipType rotateFlipType) { // clone the Image instance, since we don't want to resize the original Image instance var rotatedImage = image.Clone() as System.Drawing.Image; //rotatedImage.RotateFlip(rotateFlipType); var newSize = CalculateResizedDimensions(rotatedImage, width, height); var resizedImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb); resizedImage.SetResolution(72, 72); using (var graphics = Graphics.FromImage(resizedImage)) { // set parameters to create a high-quality thumbnail graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; // use an image attribute in order to remove the black/gray border around image after resize // (most obvious on white images), see this post for more information: // http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx using (var attribute = new ImageAttributes()) { attribute.SetWrapMode(WrapMode.TileFlipXY); // draws the resized image to the bitmap graphics.DrawImage(rotatedImage, new Rectangle(new Point(0, 0), newSize), 0, 0, rotatedImage.Width, rotatedImage.Height, GraphicsUnit.Pixel, attribute); } } return resizedImage; }
public PictureBoxExtended() { InitializeComponent(); this.DoubleBuffered = true; imageAttributes = new System.Drawing.Imaging.ImageAttributes(); colorMatrix = new System.Drawing.Imaging.ColorMatrix(); }
public CMVPlayer() { InitializeComponent(); // Paint values drawArea = new Rectangle(0, 0, Width, Height); // Draw stage constants magenta = Color.FromArgb(255, 255, 0, 255); attributes = new ImageAttributes(); playTimer = new Timer(); playTimer.Interval = 1000 / 25; playTimer.Tick += new EventHandler(timerTick); DoubleBuffered = true; Reset(); cmv = new CMV(); tileset = new TileSet(); renderedTiles = new Dictionary<short, Bitmap>(); forceRedraw = true; }
public static Graphics AlphaBlend(this Graphics gr, Bitmap b, Rectangle to, Rectangle from, float opacity) { #if WINCE byte bopacity = unchecked((byte)(255 * opacity)); using (Graphics gxSrc = Graphics.FromImage(b)) { IntPtr hdcDst = gr.GetHdc(); IntPtr hdcSrc = gxSrc.GetHdc(); BlendFunction blendFunction = new BlendFunction(); blendFunction.BlendOp = (byte)BlendOperation.AC_SRC_OVER; blendFunction.BlendFlags = (byte)BlendFlags.Zero; blendFunction.SourceConstantAlpha = bopacity; blendFunction.AlphaFormat = (byte)0; try{ PlatformAPI.AlphaBlend(hdcDst, to.X, to.Y, to.Width, to.Height, hdcSrc, from.X, from.Y, from.Width, from.Height, blendFunction); }catch(Exception e){} gr.ReleaseHdc(hdcDst); gxSrc.ReleaseHdc(hdcSrc); } #else var ia = new ImageAttributes(); float[][] ptsArray = { new float[] {1, 0, 0, 0, 0}, new float[] {0, 1, 0, 0, 0}, new float[] {0, 0, 1, 0, 0}, new float[] {0, 0, 0, opacity, 0}, new float[] {0, 0, 0, 0, 1}}; ia.SetColorMatrix(new ColorMatrix(ptsArray)); gr.DrawImage(b, to, from.X, from.Y, from.Width, from.Height, GraphicsUnit.Pixel, ia); #endif return gr; }
public ButtonCell(ButtonCell bc) : base(bc) { this.m_bColor = SystemColors.ControlDark; this.m_pForeColor = SystemColors.HighlightText; this.m_pBgColor = SystemColors.ControlDark; this.m_pBorderColor = SystemColors.ControlDarkDark; this.m_text = ""; this.m_DetachImageList = new EventHandler(this.OnDetachImageList); this.m_buttonStyle = bc.m_buttonStyle; this.m_font = new Font(bc.m_font.Name, bc.m_font.Size, bc.m_font.Style); this.m_text = bc.m_text; this.m_textAlignment = bc.m_textAlignment; this.m_textPosition = bc.m_textPosition; this.m_imageAlignment = bc.m_imageAlignment; this.m_imagePosition = bc.m_imagePosition; this.m_autoResizeImage = bc.m_autoResizeImage; this.m_ia = new ImageAttributes(); this.m_bColor = bc.m_bColor; this.m_pBgColor = bc.m_pBgColor; this.m_pBorderColor = bc.m_pBorderColor; this.m_pForeColor = bc.m_pForeColor; this.m_transparentColor = bc.m_transparentColor; this.m_bAutoTransparent = bc.m_bAutoTransparent; this.m_touchMargin = bc.m_touchMargin; this.m_bPressed = bc.m_bPressed; this.m_defaultImage = bc.m_defaultImage; this.m_defaultImageVGA = bc.m_defaultImageVGA; this.m_pressedImage = bc.m_pressedImage; this.m_pressedImageVGA = bc.m_pressedImageVGA; base.Selectable = bc.Selectable; }
public Bitmap Offset(Bitmap bmpSource, Color clrScaleColor) { Bitmap bmpTemp = new Bitmap(bmpSource.Width, bmpSource.Height); //Create Temporary Bitmap To Work With ImageAttributes iaImageProps = new ImageAttributes(); //Contains information about how bitmap and metafile colors are manipulated during rendering. CMOffset = new ColorMatrix(new float[][] { new float[] {1,0,0,0,0}, new float[] {0,1,0,0,0}, new float[] {0,0,1,0,0}, new float[] {0,0,0,1,0}, new float[] { (float)clrScaleColor.R / 255, (float)clrScaleColor.G / 255, (float)clrScaleColor.B / 255, 0, 1 } }); iaImageProps.SetColorMatrix(combineColorMatrix()); //Apply Matrix Graphics grpGraphics = Graphics.FromImage(bmpTemp); //Create Graphics Object and Draw Bitmap Onto Graphics Object grpGraphics.DrawImage(bmpSource, new Rectangle(0, 0, bmpSource.Width, bmpSource.Height), 0, 0, bmpSource.Width, bmpSource.Height, GraphicsUnit.Pixel, iaImageProps); return bmpTemp; }
protected override void WndProc(ref Message m) { switch (m.Msg) { case LpsWindowsApiDefine.WM_PAINT: Bitmap bmpCaptured = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); Bitmap bmpResult = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); Rectangle r = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); CaptureWindow(this, ref bmpCaptured); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; ImageAttributes imgAttrib = new ImageAttributes(); ColorMap[] colorMap = new ColorMap[1]; colorMap[0] = new ColorMap(); colorMap[0].OldColor = Color.White; colorMap[0].NewColor = Color.Transparent; imgAttrib.SetRemapTable(colorMap); Graphics g = Graphics.FromImage(bmpResult); g.DrawImage(bmpCaptured, r, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, imgAttrib); g.Dispose(); pictureBox.Image = (Image)bmpResult.Clone(); break; case LpsWindowsApiDefine.WM_HSCROLL: case LpsWindowsApiDefine.WM_VSCROLL: this.Invalidate(); // repaint // if you use scrolling then add these two case statements break; } //switch (m.WParam.ToInt32()) //{ // case WindowsApiDefine.WM_LBUTTONDOWN: // p = new Point(Cursor.Position.X, Cursor.Position.Y); // break; //} base.WndProc(ref m); }
public static void ConvertImage(Bitmap image, Graphics g, Color ForeColor, Color BackColor, bool isActive) { using (ImageAttributes imageAttributes = new ImageAttributes()) { ColorMap[] colorMap = new ColorMap[2]; colorMap[0] = new ColorMap(); colorMap[0].OldColor = Color.FromArgb(0, 0, 0); colorMap[0].NewColor = ForeColor; colorMap[1] = new ColorMap(); colorMap[1].OldColor = image.GetPixel(0, 0); colorMap[1].NewColor = isActive ? BackColor : Color.Transparent; imageAttributes.SetRemapTable(colorMap); g.DrawImage( image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes); } }
public override Bitmap Perform(Bitmap bitmap) { // convert +/-1000 input range to a logarithmic scaled multiplier float contrastAdjusted = (float) Math.Pow(2.718281f, Contrast / 500.0f); // see http://docs.rainmeter.net/tips/colormatrix-guide/ for offset & matrix calculation float offset = (1.0f - contrastAdjusted) / 2.0f; EnsurePixelFormat(ref bitmap); using (var g = Graphics.FromImage(bitmap)) { var attrs = new ImageAttributes(); attrs.SetColorMatrix(new ColorMatrix { Matrix00 = contrastAdjusted, Matrix11 = contrastAdjusted, Matrix22 = contrastAdjusted, Matrix33 = 1.0f, Matrix44 = 1.0f, Matrix40 = offset, Matrix41 = offset, Matrix42 = offset, }); g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, attrs); } return bitmap; }
private static Bitmap Parlaklik(Bitmap bmp, int deger) { System.Drawing.Bitmap TempBitmap = bmp; float finalValue = (float)deger / 255.0f; System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height); System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap); float[][] FloatColorMatrix = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { finalValue, finalValue, finalValue, 1, 1 }, }; System.Drawing.Imaging.ColorMatrix NewColorMatrix = new System.Drawing.Imaging.ColorMatrix(FloatColorMatrix); System.Drawing.Imaging.ImageAttributes Attributes = new System.Drawing.Imaging.ImageAttributes(); Attributes.SetColorMatrix(NewColorMatrix); NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), 0, 0, TempBitmap.Width, TempBitmap.Height, System.Drawing.GraphicsUnit.Pixel, Attributes); Attributes.Dispose(); NewGraphics.Dispose(); return(NewBitmap); }
/// <summary> /// change brightness, contrast and/or gamma of a bitmap /// (see http://stackoverflow.com/questions/15408607/adjust-brightness-contrast-and-gamma-of-an-image) /// </summary> /// <param name="originalImage">image to process</param> /// <param name="brightness">new brightness (1.0 = no changes, 0.0 to 2.0)</param> /// <param name="contrast">new contrast (1.0 = no changes)</param> /// <param name="gamma">new gamma (1.0 = no changes)</param> /// <returns></returns> static internal Bitmap adjustBitmap(Bitmap originalImage, float brightness = 1.0f, float contrast = 1.0f, float gamma = 1.0f) { Bitmap adjustedImage; ImageAttributes imageAttributes; Graphics g; float adjustedBrightness; adjustedBrightness = brightness - 1.0f; // create matrix that will brighten and contrast the image float[][] ptsArray ={ new float[] {contrast, 0, 0, 0, 0}, // scale red new float[] {0, contrast, 0, 0, 0}, // scale green new float[] {0, 0, contrast, 0, 0}, // scale blue new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}}; imageAttributes = new ImageAttributes(); imageAttributes.ClearColorMatrix(); imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap); imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap); adjustedImage = new Bitmap(originalImage.Width, originalImage.Height); g = Graphics.FromImage(adjustedImage); g.DrawImage(originalImage, new Rectangle(0,0,adjustedImage.Width,adjustedImage.Height), 0,0,originalImage.Width,originalImage.Height, GraphicsUnit.Pixel, imageAttributes); g.Dispose(); return adjustedImage; }
public static Bitmap MakeGrayscale(Bitmap original) { Bitmap newBitmap = new Bitmap(original.Width, original.Height); Graphics g = Graphics.FromImage(newBitmap); ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new float[] {.3f, .3f, .3f, 0, 0}, new float[] {.59f, .59f, .59f, 0, 0}, new float[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(colorMatrix); g.DrawImage(original, new System.Drawing.Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes); g.Dispose(); return newBitmap; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// A Bitmap extension method that converts a bitmap to a gray scale image. /// </summary> /// <remarks> Aaevans, 2/16/2016. </remarks> /// <param name="bitmap"> The bitmap to act on. </param> /// <returns> A Bitmap. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static Bitmap AsGrayScaleImage(this Bitmap bitmap) { var newBitmap = new Bitmap(bitmap.Width, bitmap.Height); using (var g = Graphics.FromImage(newBitmap)) { var colorMatrix = new ColorMatrix( new[] { new[] { .3f, .3f, .3f, 0, 0 }, new[] { .59f, .59f, .59f, 0, 0 }, new[] { .11f, .11f, .11f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); var attributes = new ImageAttributes(); attributes.SetColorMatrix(colorMatrix); g.DrawImage( bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, attributes); } return newBitmap; }
public static string ConvertImage(Bitmap image) { var matrix = CreateGrayscaleMatrix(); var attributes = new ImageAttributes(); attributes.SetColorMatrix(matrix); var asciiart = new StringBuilder(); using (var gphGrey = Graphics.FromImage(image)) { var bounds = new Rectangle(0, 0, image.Width, image.Height); gphGrey.DrawImage(image, bounds, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); } int h = 0; // h := for each row int image, by image.Height and RowHeight { int w = 0; // w := for each column in image, by image.Width and ColumnWidth { var blockBrightness = GetBlockBrightness(image, h, w); var symbol = SymbolSelector.ChooseSymbol(blockBrightness); asciiart.Append(symbol); } asciiart.Append("\n"); } return asciiart.ToString(); }
private void setAlpha(float alpha) { this.imgAlpha = alpha; // Initialize the color matrix. // Note the value 0.8 in row 4, column 4. float[][] matrixItems = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, alpha, 0 }, new float[] { 0, 0, 0, 0, 1 } }; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); // Create an ImageAttributes object and set its color matrix. ImageAttributes imageAtt = new ImageAttributes(); imageAtt.SetColorMatrix( colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); this.imgAttr = imageAtt; }
private void button2_Click(object sender, EventArgs e) { begin = DateTime.Now.Ticks; Bitmap currentBitmap = new Bitmap(pictureBox1.Image); Graphics g = Graphics.FromImage(currentBitmap); ImageAttributes ia = new ImageAttributes(); float[][] colorMatrix = { new float[] {0.299f, 0.299f, 0.299f, 0, 0}, new float[] {0.587f, 0.587f, 0.587f, 0, 0}, new float[] {0.114f, 0.114f, 0.114f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }; ColorMatrix cm = new ColorMatrix(colorMatrix); ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(currentBitmap, new Rectangle(0, 0, currentBitmap.Width, currentBitmap.Height), 0, 0, currentBitmap.Width, currentBitmap.Height, GraphicsUnit.Pixel, ia); pictureBox1.Image = currentBitmap; g.Dispose(); end = DateTime.Now.Ticks; label1.Text = (end - begin) / 1000 + "毫秒"; }
/// <summary> /// Converts a bitmap into grayscale mode /// </summary> public static Bitmap CreateGrayscaleBitmap(Bitmap fromBitmap) { Bitmap newBitmap = new Bitmap(fromBitmap.Width, fromBitmap.Height); using (Graphics gr = Graphics.FromImage(newBitmap)) { //create the grayscale ColorMatrix covert ramp ColorMatrix colorMatrix = new ColorMatrix( new float[][] { new float[] {.3f, .3f, .3f, 0, 0}, new float[] {.59f, .59f, .59f, 0, 0}, new float[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); using (ImageAttributes attr = new ImageAttributes()) { attr.SetColorMatrix(colorMatrix); gr.DrawImage(fromBitmap, new Rectangle(0, 0, fromBitmap.Width, fromBitmap.Height), 0, 0, fromBitmap.Width, fromBitmap.Height, GraphicsUnit.Pixel, attr); } } return newBitmap; }
/// <summary> /// Resizes the image using a high quality. /// From http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp /// </summary> /// <param name="imageStream"></param> /// <returns></returns> internal static MemoryStream ProcessImage(MemoryStream imageStream) { var height = 100; var width = 100; Image original = Image.FromStream(imageStream); var destRect = new Rectangle(0, 0, width, height); var destImage = new Bitmap(width, height); destImage.SetResolution(original.HorizontalResolution, original.VerticalResolution); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(original, destRect, 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, wrapMode); } } MemoryStream ret = new MemoryStream(); destImage.Save(ret, original.RawFormat); ret.FlushAsync().Wait(); ret.Position = 0; return ret; }
public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft) { if (g == null) { throw new ArgumentNullException("g"); } if (backgroundImageLayout == ImageLayout.Tile) { using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile)) { if (scrollOffset != Point.Empty) { Matrix transform = brush.Transform; transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y); brush.Transform = transform; } g.FillRectangle(brush, clipRect); return; } } Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout); if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None)) { rect.X += clipRect.Width - rect.Width; } using (SolidBrush brush2 = new SolidBrush(backColor)) { g.FillRectangle(brush2, clipRect); } if (!clipRect.Contains(rect)) { if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom)) { rect.Intersect(clipRect); g.DrawImage(backgroundImage, rect); } else if (backgroundImageLayout == ImageLayout.None) { rect.Offset(clipRect.Location); Rectangle destRect = rect; destRect.Intersect(clipRect); Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size); g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel); } else { Rectangle rectangle4 = rect; rectangle4.Intersect(clipRect); Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size); g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel); } } else { ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetWrapMode(WrapMode.TileFlipXY); g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr); imageAttr.Dispose(); } }
/// <summary> /// Resizes the specified image to the specifed size. /// </summary> /// <param name="image">The image to resize.</param> /// <param name="width">The width in pixels of the resized image.</param> /// <param name="height">The height in pixels of the resized image.</param> /// <param name="dispose">The value indicating whether to dispose the specified image after returning the new resized bitmap.</param> /// <returns>The specifed image, resized to the specified size.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown when 'image' is null. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when 'width' is less than 0. /// - OR - /// Thrown when 'height' is less than 0. /// </exception> public static Bitmap ResizeImage(Image image, int width, int height, bool dispose = true) { // http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp if (image == null) throw new ArgumentNullException(nameof(image)); if (width < 0) throw new ArgumentOutOfRangeException(nameof(width), width, "'" + nameof(width) + "' cannot be less than 0."); if (height < 0) throw new ArgumentOutOfRangeException(nameof(height), height, "'" + nameof(height) + "' cannot be less than 0."); Bitmap bitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(bitmap); ImageAttributes attributes = new ImageAttributes(); #region >> Sets settings for high quality resizing bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution); graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; attributes.SetWrapMode(WrapMode.TileFlipXY); #endregion graphics.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); if (dispose) image.Dispose(); graphics.Dispose(); attributes.Dispose(); return bitmap; }
protected override void OnPaint(PaintEventArgs e) { if (IsMouseOver && Enabled) { using (Pen pen = new Pen(ForeColor)) { e.Graphics.DrawRectangle(pen, Rectangle.Inflate(ClientRectangle, -1, -1)); } } using (ImageAttributes imageAttributes = new ImageAttributes()) { ColorMap[] colorMap = new ColorMap[2]; colorMap[0] = new ColorMap(); colorMap[0].OldColor = Color.FromArgb(0, 0, 0); colorMap[0].NewColor = ForeColor; colorMap[1] = new ColorMap(); colorMap[1].OldColor = Image.GetPixel(0, 0); colorMap[1].NewColor = Color.Transparent; imageAttributes.SetRemapTable(colorMap); e.Graphics.DrawImage( Image, new Rectangle(0, 0, Image.Width, Image.Height), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, imageAttributes); } base.OnPaint(e); }
/// <summary> /// 创建缩略图 /// </summary> public void cutAvatar(string imgSrc, int x, int y, int width, int height, long Quality, string SavePath, int t) { Image original = Image.FromFile(imgSrc); Bitmap img = new Bitmap(t, t, PixelFormat.Format24bppRgb); img.MakeTransparent(img.GetPixel(0, 0)); img.SetResolution(72, 72); using (Graphics gr = Graphics.FromImage(img)) { if (original.RawFormat.Equals(ImageFormat.Jpeg) || original.RawFormat.Equals(ImageFormat.Png) || original.RawFormat.Equals(ImageFormat.Bmp)) { gr.Clear(Color.Transparent); } if (original.RawFormat.Equals(ImageFormat.Gif)) { gr.Clear(Color.White); } gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.SmoothingMode = SmoothingMode.AntiAlias; gr.CompositingQuality = CompositingQuality.HighQuality; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; using (var attribute = new System.Drawing.Imaging.ImageAttributes()) { attribute.SetWrapMode(WrapMode.TileFlipXY); gr.DrawImage(original, new Rectangle(0, 0, t, t), x, y, width, height, GraphicsUnit.Pixel, attribute); } } ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg"); if (original.RawFormat.Equals(ImageFormat.Jpeg)) { myImageCodecInfo = GetEncoderInfo("image/jpeg"); } else if (original.RawFormat.Equals(ImageFormat.Png)) { myImageCodecInfo = GetEncoderInfo("image/png"); } else if (original.RawFormat.Equals(ImageFormat.Gif)) { myImageCodecInfo = GetEncoderInfo("image/gif"); } else if (original.RawFormat.Equals(ImageFormat.Bmp)) { myImageCodecInfo = GetEncoderInfo("image/bmp"); } Encoder myEncoder = Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, Quality); myEncoderParameters.Param[0] = myEncoderParameter; img.Save(SavePath, myImageCodecInfo, myEncoderParameters); }
public static Bitmap ResizeImage(Image image, int width, int height) { var destRect = new Rectangle(0, 0, width, height); var destImage = new Bitmap(width, height); destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); graphics.Dispose(); } } return destImage; }
public static Image SetImageOpacity(Image image, float opacity) { try { //create a Bitmap the size of the image provided var bmp = new Bitmap(image.Width, image.Height); //create a graphics object from the image using (var gfx = Graphics.FromImage(bmp)) { //create a color matrix object var matrix = new ColorMatrix(); //set the opacity matrix.Matrix33 = opacity; //create image attributes var attributes = new ImageAttributes(); //set the color(opacity) of the image attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); //now draw the image gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); } return bmp; } catch { return null; } }
public void BlackAndWhite() { using (Graphics gr = Graphics.FromImage(bmp)) // SourceImage is a Bitmap object { var gray_matrix = new float[][] { new float[] { 0.299f, 0.299f, 0.299f, 0, 0 }, new float[] { 0.587f, 0.587f, 0.587f, 0, 0 }, new float[] { 0.114f, 0.114f, 0.114f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }; int width = bmp.Width; int height = bmp.Height; var ia = new System.Drawing.Imaging.ImageAttributes(); ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix)); ia.SetThreshold((float)0.8); // Change this threshold as needed var rc = new Rectangle(0, 0, bmp.Width, bmp.Height); gr.DrawImage(bmp, rc, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia); Bitmap b = new Bitmap(width, height, gr); OnImageFinished(b); } }
public static Bitmap ToGrayscale(this Bitmap original) { //create a blank bitmap the same size as original Bitmap newBitmap = new Bitmap(original.Width, original.Height); //get a graphics object from the new image Graphics g = Graphics.FromImage(newBitmap); //create the grayscale ColorMatrix System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix( new float[][] { new float[] { .3f, .3f, .3f, 0, 0 }, new float[] { .59f, .59f, .59f, 0, 0 }, new float[] { .11f, .11f, .11f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 } }); //create some image attributes System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes(); //set the color matrix attribute attributes.SetColorMatrix(colorMatrix); //draw the original image on the new image //using the grayscale color matrix g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes); //dispose the Graphics object g.Dispose(); return(newBitmap); }
internal static Image RGBToBGR(this Image bmp) { Image newBmp; if ((bmp.PixelFormat & PixelFormat.Indexed) != 0) { newBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb); } else { newBmp = bmp; } try { System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMatrix cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr); ia.SetColorMatrix(cm); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp)) { g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia); } } finally { if (newBmp != bmp) { bmp.Dispose(); } } return(newBmp); }
private void PreparePicture() { if (imgPicture != null) { bmpPicture = new Bitmap(imgPicture.Width, imgPicture.Height); iaPicture = new System.Drawing.Imaging.ImageAttributes(); } }
//***********************************鼠标落**********************************************************************************************************// private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (!cutoff) { if (e.Button == MouseButtons.Right) { if (textBox1.Text.Length != 0 && pictureBox1.Image != null) { Bitmap bt = new Bitmap(pictureBox1.Image); string myfont = textBox1.Text.Trim(); Graphics gg = Graphics.FromImage(bt); FontF = fontDialog1.Font.FontFamily; gg.DrawString(textBox1.Text.Trim(), new Font(FontF, fontSize, fontStyle), new SolidBrush(fontColor), new PointF(e.X, e.Y)); pictureBox1.Image = bt; } } else { if (moveflag == true) { start = new Point(e.X, e.Y); end = start; } int x, y; x = e.X * bitmap.Width / pictureBox1.Width; y = e.Y * bitmap.Height / pictureBox1.Height; Color c = bitmap.GetPixel(x, y); x_x = x; y_y = y; mousedown = true; if (flag == 0) { Rectangle dest2 = new Rectangle(1, 1, pictureBox2.Width, pictureBox2.Height); System.Drawing.Imaging.ImageAttributes imageattr = new System.Drawing.Imaging.ImageAttributes(); imageattr.SetGamma(1.0F); g2.DrawImage(pictureBox1.Image, dest2, x, y, pictureBox2.Width, pictureBox2.Height, GraphicsUnit.Pixel); pictureBox2.BackColor = Color.Transparent; Invalidate(true); } } } else { this.Cursor = Cursors.Cross; this.p1 = new Point(e.X, e.Y); x1 = e.X; y1 = e.Y; if (this.pictureBox1.Image != null) { HeadImageBool = true; } else { HeadImageBool = false; } } }
private void CalculateBackColors(Color backColor) { this.backColor = backColor; hilightColor = Color.FromArgb(backColor.A, Math.Min(255, (int)((float)backColor.R + hilightBrightness)), Math.Min(255, (int)((float)backColor.G + hilightBrightness)), Math.Min(255, (int)((float)backColor.B + hilightBrightness))); //hilightColor = Color.FromArgb(backColor.A, Math.Min(255, (int)((float)backColor.R + 21)), Math.Min(255, (int)((float)backColor.G + 21)), Math.Min(255, (int)((float)backColor.B + 21))); backgroundImageAttributes = GetImageAlphaAttributes(backColor.A); //overlayImageAttributes = GetImageAlphaAttributes(1.0f * ((float)backColor.A / 255.0f) * bevelOverlayImageAlpha); overlayImageAttributes = GetImageAlphaAttributes(backColor.A); }
public static void Fill(Graphics g, Rectangle rect) { if (_texture == null) { GeneratePattern(); } System.Drawing.Imaging.ImageAttributes imgAttr = new System.Drawing.Imaging.ImageAttributes(); imgAttr.SetWrapMode(WrapMode.TileFlipXY); g.FillRectangle(_texture, rect); //new Rectangle(0, 0, bmpBg.Width, bmpBg.Height)); }
private void ResetPaintImage() { if (PaintImage != null) { PaintImage.Dispose(); PaintImage = null; } if (Image != null && Image.Width > 0 && Image.Height > 0 && DrawRect.Width > 0 && DrawRect.Height > 0) { PaintImage = new Bitmap((int)DrawRect.Width, (int)DrawRect.Height); using (Graphics g = Graphics.FromImage(PaintImage)) { System.Drawing.Imaging.ImageAttributes ima = new System.Drawing.Imaging.ImageAttributes(); ColorMatrix cm = new ColorMatrix(); cm.Matrix33 = Opacity; ima.SetColorMatrix(cm); Point pt = Point.Empty; switch (FillMode) { case ImageFillMode.Center: pt = new Point((int)(DrawRect.Width - Image.Width) / 2, (int)(DrawRect.Height - Image.Height) / 2); g.DrawImage(Image, new Rectangle(pt, Image.Size), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ima); break; case ImageFillMode.Strength: g.DrawImage(Image, Rectangle.Round(DrawRect), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ima); break; case ImageFillMode.Title: ima.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile); TextureBrush brush = new TextureBrush(Image, new Rectangle(0, 0, Image.Width, Image.Height), ima); g.FillRectangle(brush, DrawRect); break; case ImageFillMode.Zoom: float scale = 1; if (Image.Width > 0 && Image.Height > 0 && DrawRect.Width > 0 && DrawRect.Height > 0) { float f1 = DrawRect.Width / Image.Width; float f2 = DrawRect.Height / Image.Height; scale = f1 > f2 ? f2 : f1; float zWidth = scale * Image.Width; float zHeight = scale * Image.Height; //RectangleF zoomRect = new RectangleF( } break; } } } else { PaintImage = null; } }
public string GetFile(int ImageId, int size) { try { System.Drawing.Image imNormal = System.Drawing.Image.FromFile(GetServerPath("/Content/Content-image/" + ImageId + ".jpg")); System.Drawing.Image iii; Double xRatio = (double)imNormal.Width / size; Double yRatio = (double)imNormal.Height / size; Double ratio = Math.Max(xRatio, yRatio); int nnx = (int)Math.Floor(imNormal.Width / ratio); int nny = (int)Math.Floor(imNormal.Height / ratio); var destRect = new System.Drawing.Rectangle(0, 0, nnx, nny); var destImage = new System.Drawing.Bitmap(nnx, nny); destImage.SetResolution(imNormal.HorizontalResolution, imNormal.VerticalResolution); using (var grapgics = System.Drawing.Graphics.FromImage(destImage)) { grapgics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; grapgics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; grapgics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grapgics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grapgics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; using (var wrapMode = new System.Drawing.Imaging.ImageAttributes()) { wrapMode.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY); grapgics.DrawImage(imNormal, destRect, 0, 0, imNormal.Width, imNormal.Height, System.Drawing.GraphicsUnit.Pixel, wrapMode); } } iii = destImage; string name = "Raccoonogram_im_" + ImageId + "_" + size + "_" + DateTime.Now; System.Text.StringBuilder sb = new System.Text.StringBuilder(); using (System.Security.Cryptography.MD5 md5hash = System.Security.Cryptography.MD5.Create()) { byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(name); byte[] hash = md5hash.ComputeHash(inputBytes); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2")); } } string file_name = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/downloads/") + sb.ToString() + ".jpg"; iii.Save(file_name); return(sb.ToString()); } catch (Exception ex) { return(ex.ToString()); } }
public static Bitmap ChangeOpacity(Image img, float opacityvalue) { Bitmap bmp = new Bitmap(img.Width, img.Height); // Determining Width and Height of Source Image Graphics graphics = Graphics.FromImage(bmp); System.Drawing.Imaging.ColorMatrix colormatrix = new System.Drawing.Imaging.ColorMatrix(); colormatrix.Matrix33 = opacityvalue; System.Drawing.Imaging.ImageAttributes imgAttribute = new System.Drawing.Imaging.ImageAttributes(); imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute); graphics.Dispose(); // Releasing all resource used by graphics return(bmp); }
/// <summary> /// 添加图片水印 /// </summary> /// <param name="path">原图片绝对地址</param> /// <param name="suiyi">水印文件</param> /// <param name="pos">水印位置</param> private static byte[] addWaterMark(Image image, string suiyi, WaterPositionMode pos) { try { Bitmap b = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(b); g.Clear(Color.White); g.DrawImage(image, 0, 0, image.Width, image.Height); System.Drawing.Image watermark = new Bitmap(suiyi); System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); 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, 1.0f, 0.0f },//设置透明度 new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; Point position = SetMarkPoint(pos, watermark, image); xpos = position.X; // ((image.Width - watermark.Width) - 50);//水印位置 ypos = position.Y; //image.Height - watermark.Height - 50;//水印位置 g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes); watermark.Dispose(); imageAttributes.Dispose(); MemoryStream ms = new MemoryStream(); b.Save(ms, ImageFormat.Bmp); byte[] byteImage = ms.ToArray(); b.Dispose(); image.Dispose(); g.Dispose(); return(byteImage); } catch (Exception ex) { MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Bmp); return(ms.ToArray()); } }
/// <summary> /// Set the opacity on the drawn image, this method updates the ImageAttributes with opacity-values and is used when sharpmap draws the image, the the wms-server /// 1.0 = No tranparency /// 0.0 = full transparency /// </summary> /// <param name="opacity"></param> public void SetOpacity(float opacity) { ColorMatrix cmxPic = new ColorMatrix(); cmxPic.Matrix33 = opacity; ImageAttributes attrs = ImageAttributes; if (attrs == null) { attrs = new System.Drawing.Imaging.ImageAttributes(); } attrs.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); ImageAttributes = attrs; }