请教一个关于TIF图片合并的问题,大侠进………………
我把一张多页TIF文件分解成单页的,其中有些页我不想要了,然后我去掉多余的页,把剩下有用的单页tif重新合并,在保留第一页和最后一页时,合并都能成功,但是假如我合并的单页tif中有第一页而没有最后一页,程序会报合并失败,但是新的tif图却合并出来了,如果没有第一页,程序报错,新的tif图也没合并出来,请问大家有遇到类似的情况吗?
代码如下:
void CGDItifDlg::OnJointif()
{
// TODO: Add your control notification handler code here
CString tifName,tmp;
CString tifPath = GetAppPath(),tifPath2;
tifPath = tifPath+"\\tif1\\mutitif.tif";
tifPath2 = GetAppPath()+"\\tif1\\";
CStringArray tifNameArr;
for ( int i=0; i<18; i++ )
{
tifName.Format("%s","mutitif_");
tmp.Format("%d",i);
tifName = tifPath2+tifName+tmp+".tif";
tifNameArr.Add(tifName);
tifName.Empty();
}
int isi = MutiTifToOneTif(tifNameArr,tifPath);
if ( isi == -1 )
{
AfxMessageBox("合并tif文件失败!");
}
}
int CGDItifDlg::MutiTifToOneTif(CStringArray& arrayImagePath,CString savePath)
{
USES_CONVERSION; //用T2W宏必须先用USES_CONVERSION。 || CString 转换为 WCHAR 方法2
//多页tif,合成一页
int iResult=1;
CString strSavePath,strExt;
CString strImagePath;
Status doStatus;
INT_PTR iArrayCount=0;
iArrayCount=arrayImagePath.GetSize();
if (iArrayCount<1)
{
AfxMessageBox(_T("文件数应大于1 !"));
return -1;
}
strSavePath=savePath;
strSavePath.MakeLower();
//扩展名
strExt=strSavePath.Right(3);
if (strExt!=_T("tif"))
{
AfxMessageBox(_T("不是TIF文件!"));
return -1;
}
CLSID encodeClsid; //文件编码器的CLSID
GetEncoderClsid(L"image/tiff",&encodeClsid);
CString * spath = &savePath;
//读取第一个文件
// Image imgTif(strImagePath);
strImagePath=arrayImagePath.GetAt(0);
//CString 转换为 WCHAR 方法1
int num;
WCHAR *wTifName;
num = MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strImagePath, -1, NULL, 0);
wTifName = new WCHAR[num];
MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strImagePath, -1, wTifName, num);
Image imgTif(wTifName);
//可参考msdn
EncoderParameters encoderParameters;
ULONG parameterValue;
encoderParameters.Count = 1;
// Initialize the one EncoderParameter object.
encoderParameters.Parameter[0].Guid = EncoderSaveFlag;
encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParameters.Parameter[0].NumberOfValues = 1;
encoderParameters.Parameter[0].Value = ¶meterValue;
parameterValue = EncoderValueMultiFrame;
doStatus=imgTif.Save(T2W((LPCTSTR)savePath),&encodeClsid,&encoderParameters);
parameterValue =EncoderValueFrameDimensionPage;
for(int i=1;i<iArrayCount;i++)
{
Image imgTif2(T2W((LPCTSTR)arrayImagePath.GetAt(i)));
doStatus=imgTif.SaveAdd(&imgTif2,&encoderParameters);
}
if( doStatus != 0 )
{
CString tmp;
tmp.Format("%d",doStatus);
AfxMessageBox("aa:" + tmp);
return -1;
}
else
{
AfxMessageBox("合并TIF成功!");
}
delete[] wTifName;
return iResult;
}
是EncoderParameters结构体的参数设置有问题吗?