如何用IImage组件来播放GIF动画,jpg,png
来源:互联网 发布:淘宝的ipad为什么便宜 编辑:程序博客网 时间:2024/06/05 19:09
如何用IImage组件来播放GIF动画
如何用IImage组件来播放GIF动画
最近小弟在网上收集资料发现IImage这个com组件相当的强大,有好多地方需要学习和分析的
哎~路还很长...
下面是播放gif动画的过程
IStream* CreateStreamByFileName(LPCTSTR strFileName)
{
HANDLE hFile = CreateFile(strFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return 0;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize == (DWORD)-1)
{
CloseHandle(hFile);
return 0;
}
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if (hGlobal == NULL)
{
CloseHandle(hFile);
return 0;
}
LPVOID pvData = GlobalLock(hGlobal);
if (pvData == NULL)
{
GlobalUnlock(hGlobal);
CloseHandle(hFile);
return 0;
}
DWORD dwBytesRead = 0;
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
if (!bRead)
{
return 0;
}
IStream* pStream = 0;
if (FAILED(CreateStreamOnHGlobal(hGlobal, TRUE, &pStream)))
{
return 0;
}
return pStream;
}
___________________________________________________
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
ImageInfo *info = NULL;
IStream* pStream = CreateStreamByFileName(L"//Windows//OemAnimationstartup.gif");
IImageDecoder* pDecoder = NULL;
UINT count = 0;
UINT size = 0;
ImageInfo ii = {0};
PropertyItem pi = {0};
GUID guid;
UINT i = 0;
IBitmapImage *bmpimg = NULL;
IImageSink *sink = NULL;
LARGE_INTEGER dlibMove = { 0, 0 };
IBasicBitmapOps *oper = NULL;
hdc = BeginPaint(hwnd, &ps);
if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory)))
{
if (SUCCEEDED(pImgFactory->CreateImageDecoder(pStream, DecoderInitFlagNone, &pDecoder)))
{
pDecoder->TerminateDecoder();
pStream->Seek( dlibMove, STREAM_SEEK_SET, NULL );
pDecoder->InitDecoder(pStream, DecoderInitFlagBuiltIn1st);
pDecoder->GetPropertyItemSize(PropertyTagFrameDelay, &size);
pDecoder->GetPropertyItem(PropertyTagFrameDelay, size, &pi);
pDecoder->GetImageInfo(&ii);
pDecoder->GetFrameDimensionsCount(&count);
pDecoder->GetFrameDimensionsList(&guid, count);
pDecoder->GetFrameCount(&guid, &count);
while(i < count)
{
pDecoder->SelectActiveFrame(&guid,i);
pImgFactory->CreateNewBitmap(ii.Width, ii.Height, PixelFormatDontCare, &bmpimg);
bmpimg->QueryInterface(IID_IImageSink, (void**)&sink);
HRESULT hr = pDecoder->BeginDecode(sink, NULL);
pDecoder->Decode();
bmpimg->QueryInterface(IID_IBasicBitmapOps, (void **) &oper);
oper->Rotate(180.0, InterpolationHintDefault, &bmpimg);//这个是将图像翻转,测试用的,不需要可以去掉
bmpimg->QueryInterface(IID_IImage, (void**)&pImage);
pImage->Draw(hdc, &winRect, NULL);
//Sleep(((long*)pi.value)[i]*10);
Sleep((10);
pDecoder->EndDecode(hr);
++i;
}
}
}
pImgFactory->Release();
pImage->Release();
pDecoder->Release();
bmpimg->Release();
sink->Release();
oper->Release();
哎~路还很长...
下面是播放gif动画的过程
IStream* CreateStreamByFileName(LPCTSTR strFileName)
{
HANDLE hFile = CreateFile(strFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return 0;
}
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (dwFileSize == (DWORD)-1)
{
CloseHandle(hFile);
return 0;
}
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if (hGlobal == NULL)
{
CloseHandle(hFile);
return 0;
}
LPVOID pvData = GlobalLock(hGlobal);
if (pvData == NULL)
{
GlobalUnlock(hGlobal);
CloseHandle(hFile);
return 0;
}
DWORD dwBytesRead = 0;
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
if (!bRead)
{
return 0;
}
IStream* pStream = 0;
if (FAILED(CreateStreamOnHGlobal(hGlobal, TRUE, &pStream)))
{
return 0;
}
return pStream;
}
___________________________________________________
IImagingFactory *pImgFactory = NULL;
IImage *pImage = NULL;
ImageInfo *info = NULL;
IStream* pStream = CreateStreamByFileName(L"//Windows//OemAnimationstartup.gif");
IImageDecoder* pDecoder = NULL;
UINT count = 0;
UINT size = 0;
ImageInfo ii = {0};
PropertyItem pi = {0};
GUID guid;
UINT i = 0;
IBitmapImage *bmpimg = NULL;
IImageSink *sink = NULL;
LARGE_INTEGER dlibMove = { 0, 0 };
IBasicBitmapOps *oper = NULL;
hdc = BeginPaint(hwnd, &ps);
if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **)&pImgFactory)))
{
if (SUCCEEDED(pImgFactory->CreateImageDecoder(pStream, DecoderInitFlagNone, &pDecoder)))
{
pDecoder->TerminateDecoder();
pStream->Seek( dlibMove, STREAM_SEEK_SET, NULL );
pDecoder->InitDecoder(pStream, DecoderInitFlagBuiltIn1st);
pDecoder->GetPropertyItemSize(PropertyTagFrameDelay, &size);
pDecoder->GetPropertyItem(PropertyTagFrameDelay, size, &pi);
pDecoder->GetImageInfo(&ii);
pDecoder->GetFrameDimensionsCount(&count);
pDecoder->GetFrameDimensionsList(&guid, count);
pDecoder->GetFrameCount(&guid, &count);
while(i < count)
{
pDecoder->SelectActiveFrame(&guid,i);
pImgFactory->CreateNewBitmap(ii.Width, ii.Height, PixelFormatDontCare, &bmpimg);
bmpimg->QueryInterface(IID_IImageSink, (void**)&sink);
HRESULT hr = pDecoder->BeginDecode(sink, NULL);
pDecoder->Decode();
bmpimg->QueryInterface(IID_IBasicBitmapOps, (void **) &oper);
oper->Rotate(180.0, InterpolationHintDefault, &bmpimg);//这个是将图像翻转,测试用的,不需要可以去掉
bmpimg->QueryInterface(IID_IImage, (void**)&pImage);
pImage->Draw(hdc, &winRect, NULL);
//Sleep(((long*)pi.value)[i]*10);
Sleep((10);
pDecoder->EndDecode(hr);
++i;
}
}
}
pImgFactory->Release();
pImage->Release();
pDecoder->Release();
bmpimg->Release();
sink->Release();
oper->Release();
- 如何用IImage组件来播放GIF动画,jpg,png
- 显示 jpg、png、gif 图片及 gif 动画
- Movie来播放GIF动画
- 如何用Photoshop制作GIF动画
- GIF、JPG、PNG区别
- GIF、JPG、PNG 比较
- GIF、JPG、PNG 比较
- GIF、JPG和PNG
- gif-jpg-png区别
- 如何用Java对图片jpg, gif进行压缩
- 使用IIMAGE接口播放动画
- 我的手机开发(九)——使用IImage组件播放GIF
- Android 扩展ImageView来播放gif动画
- php图片等比压缩代码,支持jpg,png,gif,验证gif动画
- php图片等比压缩代码,支持jpg,png,gif,验证gif动画
- JPG,PNG,GIF,WBMP,BMP
- png gif jpg图片区别
- png、jpg、gif那些事情
- 使用 Forms 身份验证的一点点心得
- Linux 2.6 字符设备驱动程序
- 主机windows与虚拟机linux利用shared folders共享文件(转贴)
- 操作变量要先判断Null值
- 必须掌握的八个【cmd 命令行】
- 如何用IImage组件来播放GIF动画,jpg,png
- 使用开源产品搭建java开发环境
- .Net 调式案例—实验2 崩溃(Crash)复习回顾
- Windows服务程序的原理及实现
- "missing separator. Stop"问题的解决
- C#开发WPF/Silverlight动画及游戏系列教程(转)
- 知足常乐
- mysql的slow-query中的一个现象
- 中国缺乏独立游戏制作大环境(转载)