嵌入式图像问题。 [英] Embedded image issues.

查看:77
本文介绍了嵌入式图像问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

  我对c ++比较陌生,我的主要语言是VB。

  我的目标是有一个图片框( pic_Swap ),当鼠标移过它时图像会发生变化,当鼠标有鼠标时,它会恢复到
原始 。左 使用VB,可以很容易地使用嵌入式资源图像,但我已经用c ++打了一个砖墙!

  我最初的尝试导致必须使用2个隐藏的图片框( pic_In &
pic_Out 并嵌入适当的图像)并将其图像文件复制到
pic_Swap

  在我使用的InitializeComponent部分中:

Hello all,
   I'm relatively new to c++, my main language being VB.
   My goal is to have a picturebox (pic_Swap) whose image changes when the mouse goes over it and restores to the original when the mouse has left.  With VB one can use embedded resource images very easily, but I have hit a brick wall with c++!
   My initial attempts resulted in having to use 2 hidden picture boxes (pic_In & pic_Out with the appropriate images embedded) and copying their Image files to pic_Swap.
   In the InitializeComponent section I used:

void InitializeComponent(void)
{
   System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(mySwapper::typeid));
   //// ... removed unnecessary code...
   //
   // pic_In
   //
   this->pic_In->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pic_In.Image")));
   //
   // pic_Out
   //
   this->pic_Out->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pic_Out.Image")));
   

  以及用于图像交换的鼠标处理程序:

   and for the mouse handlers for the image swap:

private: System::Void pic_Swap_MouseEnter(System::Object^  sender, System::EventArgs^  e) {
	this->pic_Swap->Image = this->pic_In->Image;
}
private: System::Void pic_Swap_MouseLeave(System::Object^  sender, System::EventArgs^  e) {
	this->pic_Swap->Image = this->pic_Out->Image;
}

结果是我一直在 resources-> GetObject(L" pic_In。)上收到此错误消息。图片") 行:



无法找到适合指定文化或中性文化的资源。确保"MyProject.mySwapper.resources"被正确嵌入或链接到程序集"mySwapper"中在编译时,或者所有所需的卫星
程序集都是可加载和完全签名的。




 经过更多搜索后,我尝试了这一点(不使用 pic_In
pic_Out
):

The result was I kept getting this error message on theresources->GetObject(L"pic_In.Image") line:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyProject.mySwapper.resources" was correctly embedded or linked into assembly "mySwapper" at compile time, or that all the satellite assemblies required are loadable and fully signed.

 After much more searching, I tried this (without using pic_In or pic_Out):

private: System::Void pic_Swap_MouseEnter(System::Object^  sender, System::EventArgs^  e) {
	System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(mySwapper::typeid));
	this->pic_Swap->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pic_In.Image")));
}

  结果再次出现与上面相同的资源错误消息。 有没有(相对)简单的方法来使用嵌入式图像来实现所需的图像交换? 我的理想目标不是必须使用"技巧"。从  pic_In &中复制
图像 pic_Out 图片框(我必须在初始化期间隐藏它!)。

   The result is, again, the same resource error message as above.  Is there any (relatively) simple way to use embedded images to achieve the desired image swap?  My ideal aim is not to have to use the "artifice" of copying images from the pic_In & pic_Out pictureboxes (which I have to hide during initialisation!).

P.S。我已将代码保持在最低限度 - 如果需要更多,请询问。

P.S. I have kept the code to the bare minimum - if more is required please ask.

  TIA。

 TIA.





$




推荐答案

也许尝试使用表单设计器从表单中删除 pic_In pic_Out
MouseEnter MouseLeave 中注释代码。检查表单是否有效。然后使用表单设计器将
pic_In pic_Out 重新添加到任意位置并选择图像。不要手动编辑代码。检查表单是否有效并显示图像。然后在表单设计器中使它们不可见,并恢复初始代码
MouseEnter MouseLeave

Maybe try removing pic_In and pic_Out from your form using Form Designer and comment the code in MouseEnter and MouseLeave. Check that the form works. Then re-add pic_In and pic_Out using Form Designer to any location and choose the images. Do not edit the code manually. Check that the form works and the images are displayed. Then make them invisible in Form Designer and restore the initial code of MouseEnter and MouseLeave.

您也可以在新项目中尝试此操作。

You can also try this in a new project.


这篇关于嵌入式图像问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆