新手记录备忘,后续业务使用
main():
int main()
{
std::cout << "Hello World!\n";
Mat src;
src = change_special("E:/CodeDemo/2_Study/CppBmpTest/CppBmpTest/test_200_200_0x00ffff.bmp", 20, 20, 0xCD3700);
if (src.empty()) {
cout << "could not load image...." << endl;
return -1;
}
namedWindow("output", WINDOW_AUTOSIZE);
imshow("output", src);
waitKey(0);
return 0;
}
方法:
//改变指定行列颜色
Mat change_special(const char* fileName, uint32_t row, uint32_t column, uint32_t color)
{
Mat src;
src = imread(fileName);
if (src.empty()) {
cout << "could not load image...." << endl;
return src;
}
Mat dst;
dst.create(src.size(), src.type());
int height_color = src.rows;
int width_color = src.cols;
int channels = src.channels();
//这里使用了阵列改色,会隔一行修改,修改60行列
if (row <= height_color && column <= width_color) {
uint8_t newr = color >> 16;
uint8_t newg = color >> 8;
uint8_t newb = color;
src.at<Vec3b>(row, column)[0] = newb;//b
src.at<Vec3b>(row, column)[1] = newg;//g
src.at<Vec3b>(row, column)[2] = newr;//r
for (int x = row; x <= row+120; x=x+2) {
for (int y = row; y <= row + 120; y = y + 2) {
src.at<Vec3b>(x, y)[0] = newb;//b
src.at<Vec3b>(x, y)[1] = newg;
src.at<Vec3b>(x, y)[2] = newr;
}
}
}
//保存到指定图片
imwrite("E:/CodeDemo/2_Study/CppBmpTest/CppBmpTest/save.bmp", src);
return src;
}
效果: