Update documentation of imwrite()
This commit is contained in:
parent
5a7045181a
commit
2566d13100
@ -204,16 +204,17 @@ can be saved using this function, with these exceptions:
|
||||
- PNG images with an alpha channel can be saved using this function. To do this, create
|
||||
8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels
|
||||
should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below).
|
||||
- Multiple images (vector of Mat) can be saved in TIFF format (see the code sample below).
|
||||
|
||||
If the format, depth or channel order is different, use
|
||||
Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O
|
||||
functions to save the image to XML or YAML format.
|
||||
|
||||
The sample below shows how to create a BGRA image and save it to a PNG file. It also demonstrates how to set custom
|
||||
compression parameters:
|
||||
The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file.
|
||||
It also demonstrates how to save multiple images in a TIFF file:
|
||||
@include snippets/imgcodecs_imwrite.cpp
|
||||
@param filename Name of the file.
|
||||
@param img Image to be saved.
|
||||
@param img (Mat or vector of Mat) Image or Images to be saved.
|
||||
@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags
|
||||
*/
|
||||
CV_EXPORTS_W bool imwrite( const String& filename, InputArray img,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
static void createAlphaMat(Mat &mat)
|
||||
static void paintAlphaMat(Mat &mat)
|
||||
{
|
||||
CV_Assert(mat.channels() == 4);
|
||||
for (int i = 0; i < mat.rows; ++i)
|
||||
@ -21,9 +21,9 @@ static void createAlphaMat(Mat &mat)
|
||||
|
||||
int main()
|
||||
{
|
||||
// Create mat with alpha channel
|
||||
Mat mat(480, 640, CV_8UC4);
|
||||
createAlphaMat(mat);
|
||||
Mat mat(480, 640, CV_8UC4); // Create a matrix with alpha channel
|
||||
paintAlphaMat(mat);
|
||||
|
||||
vector<int> compression_params;
|
||||
compression_params.push_back(IMWRITE_PNG_COMPRESSION);
|
||||
compression_params.push_back(9);
|
||||
@ -37,9 +37,18 @@ int main()
|
||||
{
|
||||
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
|
||||
}
|
||||
|
||||
if (result)
|
||||
printf("Saved PNG file with alpha data.\n");
|
||||
else
|
||||
printf("ERROR: Can't save PNG file.\n");
|
||||
|
||||
vector<Mat> imgs;
|
||||
imgs.push_back(mat);
|
||||
imgs.push_back(~mat);
|
||||
imgs.push_back(mat(Rect(0, 0, mat.cols / 2, mat.rows / 2)));
|
||||
imwrite("test.tiff", imgs);
|
||||
printf("Multiple files saved in test.tiff\n");
|
||||
|
||||
return result ? 0 : 1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user