mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Update documentation
This commit is contained in:
@@ -197,48 +197,7 @@ should have alpha set to 0, fully opaque pixels should have alpha set to 255/655
|
||||
|
||||
The sample below shows how to create such a BGRA image and store to PNG file. It also demonstrates how to set custom
|
||||
compression parameters :
|
||||
@code
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void createAlphaMat(Mat &mat)
|
||||
{
|
||||
CV_Assert(mat.channels() == 4);
|
||||
for (int i = 0; i < mat.rows; ++i) {
|
||||
for (int j = 0; j < mat.cols; ++j) {
|
||||
Vec4b& bgra = mat.at<Vec4b>(i, j);
|
||||
bgra[0] = UCHAR_MAX; // Blue
|
||||
bgra[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX); // Green
|
||||
bgra[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX); // Red
|
||||
bgra[3] = saturate_cast<uchar>(0.5 * (bgra[1] + bgra[2])); // Alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argv, char **argc)
|
||||
{
|
||||
// Create mat with alpha channel
|
||||
Mat mat(480, 640, CV_8UC4);
|
||||
createAlphaMat(mat);
|
||||
|
||||
vector<int> compression_params;
|
||||
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
|
||||
compression_params.push_back(9);
|
||||
|
||||
try {
|
||||
imwrite("alpha.png", mat, compression_params);
|
||||
}
|
||||
catch (cv::Exception& ex) {
|
||||
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Saved PNG file with alpha data.\n");
|
||||
return 0;
|
||||
}
|
||||
@endcode
|
||||
@include snippets/imgcodecs_imwrite.cpp
|
||||
@param filename Name of the file.
|
||||
@param img Image to be saved.
|
||||
@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags
|
||||
|
||||
Reference in New Issue
Block a user