Qimage Color Convert to Gray to grayscale

Source: Internet
Author: User
Tags scale image

In Qt, we sometimes need to change the color of the Qimage class to grayscale, at first I was thinking of using the Qimage member function Converttoformat(), but tried a lot of parameters, the return to the conversion of the picture is a problem, not what we want gray-scale image, If you have successfully converted a grayscale image using the member function, please write your method in the comment area and let the blogger learn. Then there is a stupid way, is to manually r,g,b the value of the average, and then use the average to update each pixel value, you can also get a grayscale image. See the code below:

// image is the input color image, IMG is output grey image qimage img (image);  for (int0; i < img.width (); + +i)    {for (int0; j < Img.height (); + +J)        {int gray = Qgray (Img.pixel (i, J));        Img.setpixel (i, J, Qcolor (Gray, Gray, gray). RGB ());}    }

Qimage Color Convert to Gray to grayscale

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.