how to add resources and to use them

后端 未结 1 739
轻奢々
轻奢々 2020-12-18 00:16

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

1条回答
  •  爱一瞬间的悲伤
    2020-12-18 00:46

    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"
    

    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.

    Now, in Delphi, 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');

    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}
    

    0 讨论(0)
提交回复
热议问题