本文介绍了如何添加和使用资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想添加2张图像作为资源

In my application i want to add 2 images as resources

我要使用这些图像,当我在应用程序中单击是按钮时,第一个图像将设置为墙纸,当我在应用程序中单击否按钮时,第二张图片将被设置为桌面墙纸

I want to use those images ,when i click yes button in my application first image will be set as wallpaper and when i click on No button in my application second image will be set as desktop wallpaper

预先感谢

注意事项

推荐答案

最简单的方法是创建一个文本文件并将其命名为resources.rc或其他名称(只要与您的项目文件名称不同,因为它已经拥有自己的资源文件。)

The easiest way is to create a text file and name it resources.rc or something (as long as it isn't the same name as your project file as that already has a resource file of its own).

如果要添加图像,则需要添加这样的行:

If you're adding images, you'll need to add lines such as:

IMG_1 BITMAP "c:\my files\image1.bmp"
IMG_2 RCDATA "c:\my files\image2.jpg"

请注意,第一个参数是唯一标识资源名称。
第二个参数是资源类型。一些常量可用,例如BITMAP和AVI。对于其他,请使用RCDATA。
第三个参数是资源的完整路径和文件名。

Note that the first parameter is an unique identifying resource name.The second parameter is the resource type. Some constants are available such as BITMAP and AVI. For others, use RCDATA.The third parameter is the full path and file name of the resource.

现在,在Delphi中,您可以将该.rc文件添加到项目中。项目经理。

Now, in Delp you can add this .rc file to your project in the project manager.

要使用资源,您需要根据资源类型使用不同的方法。

To use the resources, you need different methods according to the resource type.

要加载位图,您可以使用:

To load a bitmap, you can use:

imgWallpaper1.Picture.Bitmap.LoadFromResourceName(HInstance,'IMG_1');

要加载JPEG,您需要像这样转换它:

To load a JPEG, you need to convert it like this:

var
   jpgLogo: TJpegImage;
   RStream: TResourceStream;
begin
     RStream := TResourceStream.Create(HInstance, 'IMG_2', RT_RCDATA);
     Try
        jpgLogo := TJpegImage.Create;
        Try
           jpgLogo.LoadFromStream(RStream);
           imgLogo.Picture.Graphic := jpgLogo;
        Finally
           jpgLogo.Free;
        End;
     Finally
        RStream.Free;
     End; {Try..Finally}

这篇关于如何添加和使用资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:07