当前位置:网站首页>QT picture background color pixel processing method

QT picture background color pixel processing method

2022-07-07 16:58:00 God port

Preface

stay qt In development , We often deal with background pictures , For example, I just want to get a part of the picture , Next, we use the most original image processing method to achieve the effect .

step

Let's put an original picture first
 Insert picture description here
Then we want to change the white part into the background color
Ideas :
Get all the pixels of this picture , For each pixel rgb Color judgment , If it's the color you want to change , Then we will change this pixel into a transparent color ( Or the color you want to change )
Code

	QImage image(":/CustomAddControl/1.bmp");// Load the original image 
	int w, h;
	// Get the width and height of the picture 
	w = image.width();
	h = image.height();
	// Traverse every pixel 
	for (int i = 0; i < h; i++)
	{
    
		for (int j = 0; j < w; j++)
		{
    
			QRgb rgb = image.pixel(j, i);
			if (rgb == 0xFFFFFFFF)  // If it matches the background color 
			{
    
				image.setPixel(j, i, 0x00000000);// This pixel is set to transparent 
			}
		}
	}
	QPixmap tempPixmap = QPixmap::fromImage(image);// Processed pictures 

And then we use label Show contrast effect :
 Insert picture description here
obviously , We found that the white and other areas of the original image became transparent and were covered by the background color , In this way, we can achieve a simple image embedding effect .

summary

This treatment is relatively primitive , We can filter pictures based on this object 、 To strengthen 、 A series of image processing technologies such as sawtooth , Just multiply the pixels by an image processing matrix , The specific algorithm can search by itself , This article will not explain too much .

原网站

版权声明
本文为[God port]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071512254927.html