Extracting Single Images from a CImageList object

工作需要,从网上查找到该功能,特转载到空间,以后方便查找。


This will show you how extract an individual CBitmap from a CImageList object

Introduction

While working on a project of mine using skinned buttons, I ran into problems when I tried to use a CImageList as the source of the state images.

The CImageList does not provide any direct access to the separate images within the list. I searched, and searched and searched and search... well you get the idea... Anyway after banging my head against the keyboard for 4 days, I finally found a solution.

The GetImageFromList function

The result of my headaches is the GetImageFromList function. If you are familiar with using CDCs then you are probably already calling this an obvious solution - but then, why are you reading this article in the first place?

Here is the function I managed to come up with (with the help of sites like this):

It takes 3 parameters, and returns nothing.

  • lstImages: A pointer to the CImageList object containing all of the images.
  • nImage: The index of the image that is going to be extracted.
  • destBitmap: A pointer to the CBitmap object that is going to contain the extracted image.

The function makes a copy of the image list, and moves the requested image to the front of that list.

It then draws the requested image into the destination bitmap.

oid CMyWindowClass::GetImageFromList(CImageList *lstImages, 
                             int nImage, CBitmap* destBitmap)
{    
     //First we want to create a temporary image list we can manipulate

     CImageList tmpList;
     tmpList.Create(lstImages);
     
    //Then swap the requested image to the first spot in the list 

    tmpList.Copy( 0, nImage, ILCF_SWAP );
    
    //Now we need to get som information about the image 

    IMAGEINFO lastImage;
    tmpList.GetImageInfo(0,&lastImage);
    
    //Heres where it gets fun

    //Create a Compatible Device Context using 

    //the valid DC of your calling window

    CDC dcMem; dcMem.CreateCompatibleDC (GetWindowDC()); 
    
    //This rect simply stored the size of the image we need

    CRect rect (lastImage.rcImage);
    
    //Using the bitmap passed in, Create a bitmap 

    //compatible with the window DC

    //We also know that the bitmap needs to be a certain size.

    destBitmap->CreateCompatibleBitmap (this->GetWindowDC(), 
                                      rect.Width (), rect.Height ());
    
    //Select the new destination bitmap into the DC we created above

    CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
    
    //This call apparently "draws" the bitmap from the list, 

    //onto the new destination bitmap

    tmpList.DrawIndirect (&dcMem, 0, CPoint (0, 0), 
           CSize (rect.Width (), rect.Height ()), CPoint (0, 0));
    
    
    //cleanup by reselecting the old bitmap object into the DC

    dcMem.SelectObject (pBmpOld);
}

It looks big, but remove the comments and you have a mere 12 lines of code.

Conclusion

I hope that this article can save at least one person from going through what I went through to find the answer.

Good Luck, and Happy Coding!!

Canada

Member


http://www.codeproject.com/KB/graphics/getimagefromlist.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
从扩散模型中提取训练数据是指从已有的扩散模型中提取出用于训练机器学习模型的数据集的过程。 扩散模型是一种模拟现实中扩散现象的数学模型,例如在金融学中用于模拟股票价格的变动,或者在生物学中用于模拟物质在细胞中的扩散。 在提取训练数据的过程中,首先要确定所需的特征和目标变量。特征是用于描述扩散模型状态的变量,可以是时间、位置、扩散系数等。目标变量则是我们希望预测或分析的变量,例如股票价格的变化趋势或物质的浓度分布。 接下来,我们需要从扩散模型中获取实际观测或模拟得到的数据。这些数据可以包括已知的扩散模型状态和对应的目标变量,或者通过模型模拟生成的数据。在金融领域,可以使用已有的交易数据作为输入,例如历史股价、交易量等。在生物学领域,则可以使用实验测得的物质浓度数据。 在数据获取之后,我们可以对数据进行预处理,例如处理缺失值、去除异常值等。然后,根据所选的机器学习算法,可以将数据集分为训练集和测试集。训练集用于训练模型,而测试集用于评估模型的性能。 最后,我们可以利用提取的训练数据来训练机器学习模型,例如使用监督学习算法来进行回归或分类任务。通过训练模型,我们可以学习到扩散模型中隐藏的模式和规律,从而可以对未知数据进行预测或分析。 总之,从扩散模型中提取训练数据是一种得到可以用于机器学习的数据集的过程,可以帮助我们理解和预测扩散现象。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值