`
- 浏览:
915306 次
-
#include<vector>
classCImageLoader
{
protected:
/**////Fullpathweretheimagesandiconsarestored
CStringm_sPath;
/**////ListwithalltheBmpfoundinm_sPath
std::vector<CString>m_BmpNameList;
/**////Listwithalltheicofoundinm_sPath
std::vector<CString>m_IcoNameList;
/**//**
*Iffillsthea_fileListwithallthefileswithextensiona_sExtension
*foundintthepathm_sPath
*@parama_fileList:std::vector<CString>&wherethefilenameswillbestored
*@parama_sExtension:CStringwiththeextensionofthefilestofound
*@returnbooltrueifallok
*/
boolGetFiles(std::vector<CString>&a_fileList,CStringa_sExtension);
public:
CImageLoader();
~CImageLoader();
/**//**
*Loadabitmapintothestatic
*@parama_Static:CStatic*inwhichthebitmapwillbeloaded
*@parama_iIndex:intwiththeindexofbitmaptoload.Ifitis-1
*thenitwilltakeonebmprandomly.Defaultvalue:-1
*@returnboolindicatingifitloadthebitmapcorrectly.
*/
boolSetBitmap(CStatic*a_Static,inta_iIndex=-1);
/**//**
*Changetheactualcursorforanewicothatisinthe
*@parama_iIndex:intpositioninthearray.Ifitis-1thenitwilltakeone
*bmprandomly.Defaultvalue-1.
*/
voidNewCursor(inta_iIndex=-1);
/**//**
*ItreturnsanameofaBmp.
*@parama_iIndex:intpositionoftheBMPnametoreturninthearray.
*Ifitis-1thenitwillreturnanamerandomly.Defaultvalue-1.
*@returnCStringwiththeBMPname
*/
CStringGetBmpName(inta_iIndex=-1);
/**//**
*ItreturnsanameofaIco.
*@parama_iIndex:intpositionoftheICOnametoreturninthearray.
*Ifitis-1thenitwillreturnanamerandomly.Defaultvalue-1.
*@returnCStringwiththeICOname
*/
CStringGetIcoName(inta_iIndex=-1);
/**//**
*ItreturnthenumberofBMPnamesstoredintheattributem_BmpNameListt
*@returnintwiththelengtgofm_BmpNameList
*/
intGetBmpListSize();
/**//**
*ItreturnthenumberofBMPnamesstoredintheattributem_IcoNameList
*@returnintwiththelengtgofm_IcoNameList
*/
intGetIcoListSize();
//Accesors
/**////WriteAccesorform_sPathattribute
voidSetPath(CStringa_sPath);
/**////ReadAccesorform_sPathattribute
CStringGetPath();
};
CImageLoader::CImageLoader()
{
}
CImageLoader::~CImageLoader()
{
}
boolCImageLoader::GetFiles(std::vector<CString>&a_fileList,CStringa_sExtension)
{
boolbtmpOk;
try
{
a_fileList.clear();
WIN32_FIND_DATAtmpFileFindData;
//FoundforPath/*.Extension
CStringstmpFiles=m_sPath+CString("*.")+a_sExtension;
HANDLEtmpHdFind=FindFirstFile(stmpFiles,&tmpFileFindData);
boolbtmpFi=(tmpHdFind==INVALID_HANDLE_VALUE);
while(!btmpFi)
{
//Ifwefoundafileanditisnotadirectory,weputitintothevector.
CStringstmpFileName=tmpFileFindData.cFileName;
if(!((tmpFileFindData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY))
a_fileList.push_back(m_sPath+stmpFileName);//保存找到的文件
btmpFi=(FindNextFile(tmpHdFind,&tmpFileFindData)==0);
}
btmpOk=true;
}
catch()
{
btmpOk=false;
}
returnbtmpOk;
}
boolCImageLoader::SetBitmap(CStatic*a_Static,inta_iIndex/**//*=-1*/)
{
boolbtmpOk;
try
{
CStringstmpBMP=GetBmpName(a_iIndex);
HANDLEtmphBMP1=LoadImage(NULL,stmpBMP,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
HANDLEtmphBMP2=a_Static->SetBitmap((HBITMAP)tmphBMP1);
if(tmphBMP2!=NULL)
DeleteObject(tmphBMP2),tmphBMP2=NULL;
a_Static->CenterWindow();
}
catch()
{
btmpOk=false;
}
returnbtmpOk;
}
voidCImageLoader::NewCursor(inta_iIndex/**//*=-1*/)
{
CStringstmpICO=GetIcoName(a_iIndex);
HANDLEtmphICO=LoadImage(NULL,stmpICO,IMAGE_CURSOR,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
if(tmphICO!=NULL)
{
DestroyCursor(GetCursor());
SetCursor((HICON)tmphICO);
}
}
CStringCImageLoader::GetBmpName(inta_iIndex/**//*=-1*/)
{
CStringstmpRes="";
if(m_BmpNameList.size()>0)
{
intitmpIndex=a_iIndex;
if((itmpIndex<0)||(itmpIndex>=m_BmpNameList.size()))
itmpIndex=rand()%(m_BmpNameList.size());//随机
stmpRes=m_BmpNameList[itmpIndex];
}
returnstmpRes;
}
CStringCImageLoader::GetIcoName(inta_iIndex/**//*=-1*/)
{
CStringstmpRes="";
if(m_IcoNameList.size()>0)
{
intitmpIndex=a_iIndex;
if((itmpIndex<0)||(itmpIndex>=m_IcoNameList.size()))
itmpIndex=rand()%(m_IcoNameList.size());
stmpRes=m_IcoNameList[itmpIndex];
}
returnstmpRes;
}
intCImageLoader::GetBmpListSize()
{
returnm_BmpNameList.size();
}
intCImageLoader::GetIcoListSize()
{
returnm_IcoNameList.size();
}
//ACCESSORS
voidCImageLoader::SetPath(CStringa_sPath)
{
m_sPath=a_sPath;
//确保最后以'/'结束
if(m_sPath[m_sPath.GetLength()-1]!='//')
m_sPath+="//";
GetFiles(m_BmpNameList,"bmp");
GetFiles(m_IcoNameList,"ico");
}
CStringCImageLoader::GetPath()
{
returnm_sPath;
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
Android 强大的图片加载类 图库效果,详细的Handler操作案例。
自定义的一个图片加载动画,包括swift和OC
可以实现向Gridview和其他常用图片控件中加载图片,不影响其他信息的加载;加载后在本地储存,下次加载图片会从本地获取;
又一个小巧的图片预加载类
Android 演示异步加载图片的实现 附源代码,这里主要是演示ListView的异步加载图片功能,异步加载一个view时,如果view里面有EditText,EditText在每次加载view都会触发焦点,这时候异步就会出错。可能我这样说不太...
MFC通过图片控件加载png图片的类,可以指定宽度高度,可以自适应图片大小
给大家分享一个轻量级图片加载类 ImageLoader,需要的朋友可以参考下
众所周知volley提供了一个ImageLoader类用于网络图片的加载,本质上也是用消息队列的那一套去进行图片请求,只是请求以后做了一些图片本地缓存、缩放、错位处理等内容。 下面我们来看一个简单的加载例子:
Glide图片加载库的封装类,占位符 不会覆盖CircleImageView,支持直接加载静态图、动态图到View,或者获取Bitmap,Drawable。
图片加载显示的类,加入工程后声明使用,NEW 个新实例,load,show即显示出来了
一个很好用的开源图片异步加载工具类,里面附有使用DEMO。
很方便加载各类图片文件
利用IPicture接口加载、显示图片,可加载jpg、bmp、png等图片,gif图片显示第一帧。将所有操作封装为CPicture类,定义变量后,使用LoadPicture即可载入图片,使用ShowPicture显示图片到指定位置。 并附上demo,工程...
代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/38476887 有问题博客中留言
题库类App中比较头疼的公式问题,关于题干和选项中对含有数学和化学公式TextView加载Html图文混排的处理方式(Svg图片、Base64图片、png图片的处理,以及针对公式不自动换行问题的处理)
很详细的实现了flex游戏的预加载,可以使用图片,也可以重绘技术,任你选择
这个本人封装的用2张imageView就实现的轮播图,里面有两个文件夹,一个加载本地图片的封装,一个是加载网络图片的封装。本人为每一个封装都留有了一个block块接口,使用其可以做到与外界其他类配合实现自定义功能,...
异步加载图片(网络、本地),自己定制,可以盗网络链接,无视网络电子狗。
这个本人封装的用3张imageView就实现的轮播图,里面有三个文件夹,一个加载本地图片的封装,一个是加载网络图片的封装,最后一个是加载网络图片带定时器的封装。本人为每一个封装都留有了一个block块接口,使用其...
大量图片快速加载工具类例子