Example of grayscale algorithm for C # color image

Source: Internet
Author: User

In this paper, the implementation method of C # Color image grayscale is described. Share to everyone for your reference. Here's how:

The main function code is as follows:


The code is as follows:

public static Bitmap Makegrayscale (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;

}

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Example of grayscale algorithm for C # color image

This address: http://www.paobuke.com/develop/c-develop/pbk23444.html






Related content solutions to path problems when connecting to FTP in C # custom logging C # implements Ruby's negative indexer C # implements a method to get the same name property in different objects
C # How to implement Chinese characters to pinyin or Pinyin first letter C #? D??? 3?? èí?tê?? Ò?°2x°êμ?? ′ú???? íc# implementation of custom serialization ISerializable the serialized generic class instance implemented by C #

Example of grayscale algorithm for C # color image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.