以下是使用LibTiff与OpenCV在win32控制台程序中实现tif文件与jpg文件之间的转换。
将一个tif文件拆分为一或多张jpg图片:
#include <afxwin.h>
#include <afx.h>
#include "tiffio.h"
#include <iostream>
#include <windef.h>
#include <wingdi.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc//imgproc.hpp>
void Tiff2JpgByLibtiffAndCV(TIFF *tiff, int pageIndex, const std::string &imgPath)
{
TIFFSetDirectory(tiff, pageIndex);
int width = 0;
int height = 0;
TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height);
int pixelCount = width*height;
uint32* srcImg