本文介绍了GDIPLUS - 关于图像:图像仅限于对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像是否限制在对象上?

the Image is limited on objects?

我正在我的图像类上使用它。每个控件都有它并且用于添加菜单(我的图像(参见低位差异)类返回HBITMAP。但似乎限制了对象的数量。有人可以向我解释吗?

i'm using it on my image class. every controls have it and for add on menus too(my image(see the diference on lowcase) class return HBITMAP. but seems limited on number of objects. can anyone explain to me?

(如果你需要,我可以显示我如何读取文件)

(if you need, i can show how i read the files)

推荐答案

class image { private: ULONG_PTR m_gdiplusToken; Gdiplus::GdiplusStartupInput gdiplusStartupInput; BitmapDC HBitmap; Image *img=NULL; bool isimgused=false; bool isGDIPLUSIniciated=false; int imageheight=0; int imageweight=0; int framecount=0; int intSelectFrame=0; vector<long> framedelay{0}; string strfilename=""; Gdiplus::Color clrBackColor=Gdiplus::Color::Blue; bool blnTransparent=true; HPEN imgPen; HBRUSH imgBrush; CHOOSEFONT chFont; HICON hIcon; HBITMAP hbmMask; int intRotate=0; Timer tmrAnimation; static int imagecount; void UpdateReturnBitmap() { HDC dstdc = CreateCompatibleDC(HBitmap); // Note: compatible to the dc in question HGDIOBJ hold = SelectObject(dstdc,hbmMask); BitBlt(dstdc,0,0,imageweight, imageheight, HBitmap,0,0, SRCCOPY); SelectObject(dstdc,hold); // Note: you cannot select a bitmap twice into different dc, hence unselect it here DeleteDC(dstdc); } void readimagefile(string filename) { intSelectFrame=0; framecount=0; framedelay.clear(); tmrAnimation.Stop(); if(isGDIPLUSIniciated==false) { Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); isGDIPLUSIniciated=true; } if (isimgused==true) delete img; strfilename=filename; //icon: if(toupper(filename[filename.size()-3])=='I' && toupper(filename[filename.size()-2])=='C' && toupper(filename[filename.size()-1])=='O') { isimgused=false; //create the transparent icon handle HICON hicon = (HICON)LoadImage(NULL, filename.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT); ICONINFO ii; BOOL fResult = GetIconInfo(hicon, &ii); if (fResult) { BITMAP bm; fResult = GetObject(ii.hbmColor, sizeof(bm), &bm) == sizeof(bm); if (fResult) { imageweight= bm.bmWidth; imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2; } if (ii.hbmMask) DeleteObject(ii.hbmMask); if (ii.hbmColor) DeleteObject(ii.hbmColor); } HBitmap.resize(imageweight,imageheight); if(BeforeDrawImage!=NULL) BeforeDrawImage(intSelectFrame); DrawIconEx(HBitmap,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL); if(DrawImage!=NULL) DrawImage(intSelectFrame); if(AfterDrawImage!=NULL) AfterDrawImage(intSelectFrame); framecount=1; DestroyIcon(hicon); } //cursor: else if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R' ) { isimgused=false; //create the transparent icon handle HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT); ICONINFO ii; BOOL fResult = GetIconInfo(hicon, &ii); if (fResult) { BITMAP bm; fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm); if (fResult) { imageweight= bm.bmWidth; imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2; } if (ii.hbmMask) DeleteObject(ii.hbmMask); if (ii.hbmColor) DeleteObject(ii.hbmColor); } HBitmap.resize(imageweight,imageheight); if(BeforeDrawImage!=NULL) BeforeDrawImage(intSelectFrame); DrawIconEx(HBitmap,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL); if(DrawImage!=NULL) DrawImage(intSelectFrame); if(AfterDrawImage!=NULL) AfterDrawImage(intSelectFrame); framecount=1; DestroyCursor(hicon); } //others:

//这里使用了Image类....
else
{
// isimgused =真正;
Gdiplus ::图片img2(towstring(filename).c_str());
imageweight = img2.GetWidth();
imageheight = img2.GetHeight();
HBitmap.resize(imageweight,imageheight);
Gdiplus ::图形图形(HBitmap);
矩阵旋转点;
PointF rotatezeropoint = {(REAL)imageweight / 2,(REAL)imageheight / 2};
rotatepoint.RotateAt(intRotate,rotatezeropoint);
graphics.SetTransform(& rotatepoint);
if(BeforeDrawImage!= NULL)
BeforeDrawImage(intSelectFrame);
graphics.DrawImage(& img2,0,0,imageweight,imageheight);
if(DrawImage!= NULL)
DrawImage(intSelectFrame);
if(AfterDrawImage!= NULL)
AfterDrawImage(intSelectFrame);
UINT count = 0;
count = img2.GetFrameDimensionsCount();
vector< GUID> pDimensionIDs;
pDimensionIDs.resize(count);
img2.GetFrameDimensionsList(pDimensionIDs.data(),pDimensionIDs.size());
framecount = img2.GetFrameCount(pDimensionIDs.data());
UINT nSize = img2.GetPropertyItemSize(PropertyTagFrameDelay);
//分配缓冲区以接收属性项。
PropertyItem * m_pPropertyItem =(PropertyItem *)malloc(nSize);

img2.GetPropertyItem(PropertyTagFrameDelay,nSize,m_pPropertyItem);
for(int i = 0; i< framecount; i ++)
{
framedelay.push_back(((long *)m_pPropertyItem-> value)[i] * 10);
}
free(m_pPropertyItem);
img = new Image(towstring(filename).c_str());

isimgused = true;
}
DeleteBitmap(hbmMask);
hbmMask = HBITMAPfromHDC(HBitmap);
UpdateReturnBitmap();
if(framecount> 1)
{
tmrAnimation.timerprocedure = [&]()
{
static int i = 0;

SelectFrame = i;
i ++;
if(i> = framecount)
i = 0;
tmrAnimation.Interval = framedelay [i];

};
tmrAnimation.Interval = framedelay [0];
tmrAnimation.Start();
}
else
{
if(AfterDrawImage!= NULL)
AfterDrawImage(0);
}
}
///............................

//here the Image class is used.... else { //isimgused=true; Gdiplus::Image img2(towstring(filename).c_str()); imageweight=img2.GetWidth(); imageheight=img2.GetHeight(); HBitmap.resize(imageweight,imageheight); Gdiplus::Graphics graphics(HBitmap); Matrix rotatepoint; PointF rotatezeropoint={(REAL)imageweight/2,(REAL)imageheight/2}; rotatepoint.RotateAt(intRotate,rotatezeropoint); graphics.SetTransform(&rotatepoint); if(BeforeDrawImage!=NULL) BeforeDrawImage(intSelectFrame); graphics.DrawImage(&img2, 0,0,imageweight,imageheight); if(DrawImage!=NULL) DrawImage(intSelectFrame); if(AfterDrawImage!=NULL) AfterDrawImage(intSelectFrame); UINT count = 0; count = img2.GetFrameDimensionsCount(); vector<GUID> pDimensionIDs; pDimensionIDs.resize(count); img2.GetFrameDimensionsList(pDimensionIDs.data(), pDimensionIDs.size()); framecount=img2.GetFrameCount(pDimensionIDs.data()); UINT nSize = img2.GetPropertyItemSize(PropertyTagFrameDelay); // Allocate a buffer to receive the property item. PropertyItem *m_pPropertyItem = (PropertyItem*) malloc(nSize); img2.GetPropertyItem(PropertyTagFrameDelay, nSize, m_pPropertyItem); for(int i=0;i<framecount;i++) { framedelay.push_back(((long*) m_pPropertyItem->value)[i] * 10); } free(m_pPropertyItem); img=new Image(towstring(filename).c_str()); isimgused=true; } DeleteBitmap(hbmMask); hbmMask = HBITMAPfromHDC(HBitmap); UpdateReturnBitmap(); if(framecount>1) { tmrAnimation.timerprocedure=[&]() { static int i=0; SelectFrame=i; i++; if(i>=framecount) i=0; tmrAnimation.Interval=framedelay[i]; }; tmrAnimation.Interval=framedelay[0]; tmrAnimation.Start(); } else { if(AfterDrawImage!=NULL) AfterDrawImage(0); } }///............................

我的整个应用程序可以使用3个动画gif的图像(具有相同的文件名和文件夹)。

my entire application can use 3 animated gif's images(with same file name and folder).

在这一刻我用3动画图像+ 2个ico图像文件。

in these moment i use that 3 animated images + 2 ico image files.

我可以看到所有5个图像。但如果我使用4个动画图像和1个图标...只有1个动画图像没有显示动画..为什么?这些是图像对象数限制还是什么?

i can see all the 5 images. but if i use 4 animated images and 1 icon... only 1 animated image isn't showed animated.. why? is these an Image object count limitation or something?

(我使用的是Windows 7)

(i use windows 7)


这篇关于GDIPLUS - 关于图像:图像仅限于对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 16:01