zoukankan      html  css  js  c++  java
  • bmp与png格式转换



    BOOL BmpToPNG(wchar_t* strBmpFile, wchar_t* strPngFile) { FILE* cbfBmp = _wfopen(strBmpFile, L"rb"); FILE* cbfImage = _wfopen(strPngFile, L"wb"); fseek(cbfBmp, 0, SEEK_END); int iBmpSize = ftell(cbfBmp); fseek(cbfBmp, 0, SEEK_SET); HGLOBAL hMemBmp = GlobalAlloc(GMEM_FIXED, iBmpSize); if (hMemBmp == NULL) return FALSE; IStream* pStmBmp = NULL; CreateStreamOnHGlobal(hMemBmp, FALSE, &pStmBmp); if (pStmBmp == NULL) { GlobalFree(hMemBmp); fclose(cbfBmp); fclose(cbfImage); return FALSE; } BYTE* pbyBmp = (BYTE*)GlobalLock(hMemBmp); fread(pbyBmp, iBmpSize, 1, cbfBmp); Image* imImage = NULL; imImage = Image::FromStream(pStmBmp, FALSE); if (imImage == NULL) { GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); fclose(cbfBmp); fclose(cbfImage); return FALSE; } USES_CONVERSION; CLSID clImageClsid; GetImageCLSID(A2W("image/png"), &clImageClsid); HGLOBAL hMemImage = GlobalAlloc(GMEM_MOVEABLE, 0); if (hMemImage == NULL) { pStmBmp->Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); if (imImage != NULL) delete imImage; fclose(cbfBmp); fclose(cbfImage); return FALSE; } IStream* pStmImage = NULL; CreateStreamOnHGlobal(hMemImage, TRUE, &pStmImage); if (pStmImage == NULL) { pStmBmp->Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); GlobalFree(hMemImage); if (imImage != NULL) delete imImage; fclose(cbfBmp); fclose(cbfImage); return FALSE; } imImage->Save(pStmImage, &clImageClsid); if (pStmImage == NULL) { pStmBmp->Release(); pStmImage->Release(); GlobalUnlock(hMemBmp); GlobalFree(hMemBmp); GlobalFree(hMemImage); if (imImage != NULL) delete imImage; fclose(cbfBmp); fclose(cbfImage); return FALSE; } LARGE_INTEGER liBegin = { 0 }; pStmImage->Seek(liBegin, STREAM_SEEK_SET, NULL); BYTE* pbyImage = (BYTE*)GlobalLock(hMemImage); fwrite(pbyImage, GlobalSize(hMemImage), 1, cbfImage); if (imImage != NULL) delete imImage; pStmBmp->Release(); pStmImage->Release(); GlobalUnlock(hMemBmp); GlobalUnlock(hMemImage); GlobalFree(hMemBmp); GlobalFree(hMemImage); fclose(cbfBmp); fclose(cbfImage); return TRUE; }
  • 相关阅读:
    Android开发之旅1:环境搭建及HelloWorld
    程序员学习视频教程汇总
    Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL
    查看控制层从前端传来的参数
    PostMethod和GetMethod用法
    @Transient的用法和格式化页面展示的数据格式
    修改hosts
    javascript:history.go(-1)的使用
    JsonConfig的jsonConfig.setExcludes的用法
    验证登录超时,在登录后跳转超时时的页面
  • 原文地址:https://www.cnblogs.com/ice-arrow/p/13428208.html
Copyright © 2011-2022 走看看