如何将图像与我的类的实例相关联 [英] How to I associate an image with a instance of my class

查看:74
本文介绍了如何将图像与我的类的实例相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



作为个人项目,我正在创建一个可视化油漆机器人的系统。我有一个Paint Robot类,其中包含所需的成员变量和行为。我还想将图像与可用于基本动画的机器人相关联,例如绿色活动和红色故障等。有谁知道创建图像的最佳方法?我是否必须在我的开发环境中绘制它,或者我可以使用外部编辑器将其绘制并导入到我的项目中吗?



谢谢伙计

Hi Guys,

As a personal project I'm creating a system which visualizes a paint robot. I have a Paint Robot class with the required member variables and behaviour. I would also to associate an image with the robot which can be used in basic animation, for example 'green' active & 'red' fault etc. Does anyone know the best way to create image? Do I have to draw it within my development environment or can I draw it using an external editor and import it into my project?

Thanks guys

推荐答案

要么:我更喜欢在VS外部绘制图像(因为我发现VS图像创建工具非常......嗯... 基本)并导入它们。



您在应用程序中绘制图像的具体方式取决于您,以及您的机器人类的来源。



请参阅: http:// msdn。 microsoft.com/en-us/library/vstudio/bbwz4bhx(v=vs.100).aspx [ ^ ]
Either: I prefer to draw images outside VS (because I find the VS image creation tools extremely...um...basic) and import them.

Exactly how you would paint the image in your app will depend on you, and what your Robot Class is derived from.

See here: http://msdn.microsoft.com/en-us/library/vstudio/bbwz4bhx(v=vs.100).aspx[^]


通常有很多创建图像的方法。在.NET中,您也可以使用位图在运行时创建图像。因此,在运行时也不是在.NET中创建图像的问题。



如果您使用的是Windows窗体,请使用 System.Drawing.Bitmap [ ^ ],或者如果您使用的是WPF应用程序,请使用 System.Windows.Media.Imaging.BitmapImage [ ^ ]



但更好的方法是在你的应用程序中有一个定义的图像(绿色或红色,或任何其他特定颜色) ,然后创建一个简单的R,G,B图像并将其添加到您的项目中,并将其与您的类一起使用。



还有一件事,你可以将这个Image字段添加到你的Robot类中。像这样,



Usually there are many methods of creating an image. In .NET you can use a Bitmap to create an image on the run-time too. So it is not a problem creating the images in .NET, on the run-time too.

If you're using Windows Forms, then use System.Drawing.Bitmap[^], or if you're using the WPF application, use the System.Windows.Media.Imaging.BitmapImage[^]

But a better way would be since you're going to have a defined image (either green or red, or any other particular color) in your application, then create a simple either R, G, B image and add it to your project and use it along with your class.

One more thing, you can add this Image field to your Robot class too. Like this,

public class Robot {
   // other properties, you can set it as a private one too
   public Image RobotImage { get; set; }

   // program logic and methods
}





现在每次创建一个Robot(对象)时,您都可以设置它自己的图像。这样,您就不需要进行任何其他编码,它将被设置为机器人的属性。



Now each time you will create a Robot (object) you will be able to set the Image it would have for itself. This way, you won't need to do any other coding, it will be set as a property for the Robot.


这篇关于如何将图像与我的类的实例相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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