libtiff 生成48位色tif图片
2024-10-15 02:22:42
BOOL CTifImage_48Bits::BitmapConvertTo48BitsTif(CString strImagePath, int nWidth, int nHeight, int nBpp, BYTE* pData)
{
if (nBpp != )
{
AfxMessageBox(L"只支持24位真彩图!");
return FALSE;
} if (pData == NULL)
{
AfxMessageBox(L"内存段为空!");
return FALSE;
} // 调整文件路径名称
int nFind = strImagePath.ReverseFind('.');
if (nFind == -)
{
return FALSE;
} CString strExt = strImagePath.Mid(nFind + );
strExt.MakeLower();
if (strExt != L"tif" && strExt != L"tiff")
{
strImagePath = strImagePath.Left(nFind + );
strImagePath += L"tiff";
} // 转换图像文件路径格式
LPSTR ppszA = '\0';
UnicodeToAnsi(strImagePath.GetBuffer(),&ppszA); TIFF *image; // 打开一个tif文件
if((image = TIFFOpen(ppszA, "w")) == NULL)
{
AfxMessageBox(L"不能创建TIF文件!");
return FALSE;
} const int nTifBit = ; // 分配内存
DWORD dwImgSize = nWidth * nHeight * nTifBit;
BYTE* pTifBuf = new BYTE[dwImgSize];
if (pTifBuf == NULL)
{
AfxMessageBox(L"内存分配不足!");
return FALSE;
} memset(pTifBuf, , dwImgSize); int nWidthBytes24 = (( nWidth * nBpp + ) / ) * ;
int nWidthBytes48 = nWidth * nTifBit; // 复制图像数据
BYTE* pSrc = (pData);
BYTE* pDst = (pTifBuf); int tmpSrc = ;
int tmpDst = ; for (int j = ; j < nHeight; j++)
{
tmpSrc = ;
tmpDst = ; for (int i = ; i < nWidth; i++)
{
// // RGBRGB,PhotoShop支持,但是未能实现
// pDst[tmpDst + 2] = pDst[tmpDst + 5] = pSrc[tmpSrc];
// pDst[tmpDst + 1] = pDst[tmpDst + 4] = pSrc[tmpSrc + 1];
// pDst[tmpDst + 0] = pDst[tmpDst + 3] = pSrc[tmpSrc + 2]; // RRGGBB
pDst[tmpDst + ] = pDst[tmpDst + ] = pSrc[tmpSrc];
pDst[tmpDst + ] = pDst[tmpDst + ] = pSrc[tmpSrc + ];
pDst[tmpDst + ] = pDst[tmpDst + ] = pSrc[tmpSrc + ]; tmpSrc += ;
tmpDst += ;
} pSrc -= nWidthBytes24;
pDst += nWidthBytes48;
}
// 设置图像宽度.
TIFFSetField(image, TIFFTAG_IMAGEWIDTH, nWidth); // 设置图像高度.
TIFFSetField(image, TIFFTAG_IMAGELENGTH, nHeight); // 设置一个样本所占内存的大小.
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, ); // 设置一个像素点的样本数.
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, nTifBit / ); // 设置图像的压缩方式.
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_NONE); // 设置色彩模式.
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); // 设置配置
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); // 设置Planar配置.
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); int32 iTiffCount = TIFFWriteEncodedStrip(image, , pTifBuf, nWidth * nHeight * nTifBit); TIFFClose(image); delete pTifBuf;
pTifBuf = NULL; // 如果返回值大于0,表示已经被压缩的数据大小
return (iTiffCount > );
}
最新文章
- RESTful API URI 设计的一些总结
- Java提高篇—— 简单介绍Java 的内存泄漏
- sqlalchemy 优化count()……
- 【技术贴】VirtualBox给VDI格式的虚拟机扩容
- Linux mysql常用操作命令
- [DHTML]什么是DHTML?
- java如何判断字符串是否为空的方法
- Qt实现基于G.729A(G729A)的语音聊天
- 小记css的margin collapsing
- 算法笔记_017:递归执行顺序的探讨(Java)
- ARM总线方面知识
- [最短路][部分转] P1073 最优贸易
- Jenkins构建Android项目持续集成之findbugs的使用
- 酷伯伯实时免费HTTP代理ip爬取(端口图片显示+document.write)
- 微信小程序之支付密码输入demo
- Android UiAutomator - CTS Frame
- LeetCode题解之Insert into a Binary Search Tree
- React-本地状态(state)
- ubuntu装软件包
- Windows 出现了回声 &; 微软账号无法登陆
热门文章
- poj2778
- Java for LeetCode 072 Edit Distance【HARD】
- ASP.Net核心对象之HttpResponse
- yum_rpm(利用dvd建立本地yum库)
- /bin/dd if=/path/to/source-file of=/path/to/backup-file
- jquery学习笔记---插件开发模式和结构
- android常用的一些UI调试命令am,pm
- 《数学之美》(吴军 著)读书笔记:第1章 文字和语言 vs 数字和信息
- SQL 高级查询
- WPF MVVM 关闭View