#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
void creat(Mat &image);
int main()
{
Mat image(400,400,CV_8UC4);
creat(image);
vector<int> presslev;
presslev.push_back(CV_IMWRITE_PNG_COMPRESSION);
presslev.push_back(9);
imwrite("四通道图.png",image,presslev);
Mat result = imread("四通道图.png");
imshow("result",result);
waitKey(0);
return 1;
}
void creat(Mat& image)
{
for (int i = 0; i < image.rows; i++)
{
for (int j = 0; j < image.cols; j++)
{
Vec4b &x = image.at<Vec4b>(i, j);
x[0] = UCHAR_MAX;
x[1] = saturate_cast<uchar>((float)(image.cols-j)/(float)image.cols*UCHAR_MAX);
x[2] = saturate_cast<uchar>((float)(image.rows-j)/(float)image.rows*UCHAR_MAX);
x[3] = saturate_cast<uchar>(0.5*(x[1]+x[2]));
}
}
}
