Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Animation image

I have 10 image store in resource file and i like to show them as an Animation?
0
sal1150
Asked:
sal1150
  • 15
  • 14
1 Solution
 
shaneholmesCommented:
OTTOMH

If each image is the same size, then create an image that has all of the images in one strip.

Place a TImageLIst on your form and set the height and width property that each individual
image is.  For example, if you have a strip that is 64 x 16 and each image
is 16 x 16, the strip contains 4 images, each of which is 16 wide and 16
tall, so set the imagelist height and width to 16.

 Next include the resource file in the appropriate unit, i.e. {$R
MYIMGS.RES}

Then, in your code,  Load the images in the imagelist as follows.

  MyImageList.ResourceLoad(rtBitmap, 'CLASSIMAGES', clBlue);
  if   MyImageList.Count=0 then
    MessageDlg('Could not load   My Image List',mtError,[mbOK],0);

Note: clBlue is the background color to be used for transparency purposes .


Now you have a TImageList with your images,

You can step through the imageList and display the images 1 at a time



 step through the images int he list, and display them in a TImage component

 for I:= 0 to ImageList.Count-1 do
 begin
  MyImageList.GetBitmap(I, MyImage.Picture.Bitmap)
  //maybe add somedelay here using TTimer, thread, or even just the Sleep function
 end;


Shane
Shane

0
 
sal1150Author Commented:
what means 'CLASSIMAGES'
and my images are in dll file.
i will use Ttimer to control them.
0
 
shaneholmesCommented:
Well, you never said anything about a DLL....

Anyway, they are in a resource file compiled in the DLL right?

(You already of the code to load the DLL right? OR No

If so, you can use the same code.


change

MyImageList.ResourceLoad(rtBitmap, 'CLASSIMAGES', clBlue);

to

MyImageListResInstLoad(<HANDLE of DLL goes here>, rtBitmap, CLASSIMAGES, clBlue)

CLASSIMAGES is an example name of what you called your images in the Resource file

You should have one image like i described above, called CLASSIMAGES or whatever you want to call it.

Shane
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sal1150Author Commented:
i have 33 images(bitmap) and still i cant understand u.
i do this code but no response:-


mydll := LoadLibrary('resdll.dll');
  if mydll=0 then
     raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder');

  imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);
0
 
shaneholmesCommented:
Are all the images the same size? If so what is there size?

Shane
0
 
sal1150Author Commented:
yes all with same size.
125x125
0
 
shaneholmesCommented:
Ahhh, thats a good size image. They only way you can load the TIMageList with a ResInstLoad, is if you combine all the images into one image (in this case the size would then be 4125 X 125). IN your case, you would name it '1' and recompile the resource into your DLL.

Set your TImageList & TImage height & Widths to 125

 mydll := LoadLibrary('resdll.dll');
  if mydll=0 then
     raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder')
  else
  imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);

Shane



0
 
shaneholmesCommented:
WHen the ImageList loads the 1 image in using ResInstLoad, it will automatically split the picture up into its 125 X 125 parts.

Shane
0
 
sal1150Author Commented:
mydll := LoadLibrary('resdll.dll');
  if mydll=0 then
     raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder');

  imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);
  ImageList2.GetBitmap(0, Image1.Picture.Bitmap)


still no picture in image1
0
 
sal1150Author Commented:
imagelist2.Height :=125;
imagelist1.width :=125;
0
 
shaneholmesCommented:
try

var
 bmp: TBitmap;


 imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);
 bmp:= TBitmap.Create;
 ImageList2.GetBitmap(0, bmp);
 Image1.Picture.Bitmap.Assign(bmp);
 bmp.Free;


SHane
0
 
sal1150Author Commented:
still no picture in image1
0
 
sal1150Author Commented:
in case of 'ResInstLoad' is it used 'GetBitmap' or 'GetInstRes'?
0
 
shaneholmesCommented:

 first, make sure your imagelist is getting the image from the DLL


 mydll := LoadLibrary('resdll.dll');
  if mydll=0 then
     raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder')
  else
  begin
   imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);
   ShowMessage(IntToSTr(imagelist2.Count));
 end;

SHane
0
 
shaneholmesCommented:
GetInstRes loads a particular bmp from the resource file into the imagageList.

GetBitmap gets a particular bitmap from an index in the imagelist and places it in the variable
example - ImageList2.GetBitmap(0, bmp); gets the first image and assignes it to bmp

Shane
0
 
sal1150Author Commented:
Message give me 0 value
0
 
shaneholmesCommented:
ok, if your using

 imagelist2.ResInstLoad(mydll,rtBitmap,'1', clBlue);

that means you have a resource file with an image in there called '1'.

Not with an ID of 1, a name called '1' (a string name)

Is this correct?

Shane
0
 
shaneholmesCommented:
if your app is not huge, i would entertain the thought of you zipping it up and mailing it to me and i would take a look at it for you.

you would also have to include the image and the DLL source

Shane (cladview@yahoo.com)

0
 
sal1150Author Commented:
yes that correct.
0
 
sal1150Author Commented:

sorry it is very large..but i will send resource script to check its format...

thanks
0
 
sal1150Author Commented:
dll source is:-


{$O+,D-,L-,M-,Y-,R-,Q-,U-}
library resDLL;

{$R myclock.res}
end.

//*************************************

and resourse sicript is:-


1 BITMAP 1.bmp
2 BITMAP 2.bmp
3 BITMAP 3.bmp
4 BITMAP 4.bmp
5 BITMAP 5.bmp
6 BITMAP 6.bmp
7 BITMAP 7.bmp
8 BITMAP 8.bmp
9 BITMAP 9.bmp
10 BITMAP 10.bmp
11 BITMAP 11.bmp
12 BITMAP 12.bmp
13 BITMAP 13.bmp
14 BITMAP 14.bmp
15 BITMAP 15.bmp
16 BITMAP 16.bmp
17 BITMAP 17.bmp
18 BITMAP 18.bmp
19 BITMAP 19.bmp
20 BITMAP 20.bmp
21 BITMAP 21.bmp
22 BITMAP 22.bmp
23 BITMAP 23.bmp
24 BITMAP 24.bmp
25 BITMAP 25.bmp
26 BITMAP 26.bmp
27 BITMAP 27.bmp
28 BITMAP 28.bmp
29 BITMAP 29.bmp
30 BITMAP 30.bmp
31 BITMAP 31.bmp
32 BITMAP 32.bmp
33 BITMAP 33.bmp
0
 
shaneholmesCommented:
ummmm, thats 33 images not 1

Im creating you an example now



Shane
0
 
sal1150Author Commented:
Im waiting u.
0
 
shaneholmesCommented:
you got an email address ?

Shane
0
 
sal1150Author Commented:
sal1150@hotmail.com
0
 
sal1150Author Commented:
?
0
 
shaneholmesCommented:
ah, check your email, i've been emailing you stuff regularly, but you haven't been responding.

SHane
0
 
shaneholmesCommented:
Never mind, here it is:

******* MAIN CODE HERE **************

unit UntMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Timer1: TTimer;
    procedure FormActivate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
 Form1: TForm1;
 DLLHandle: THandle;

implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);

begin
 DLLHandle:= LOadLibrary('AnimateImages.Dll');
 Image1.Picture.Bitmap.Handle := LoadImage(DLLHANDLE, 'IMAGE1',IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION or LR_DEFAULTSIZE);
 Randomize;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
 I: String;
begin
 I:= intToStr(Random(4) + 1);
 DLLHandle:= LOadLibrary('AnimateImages.Dll');
 Image1.Picture.Bitmap.Handle := LoadImage(DLLHANDLE, PChar('IMAGE' + I),IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION or LR_DEFAULTSIZE);
end;

end.

******* DLL CODE HERE **************

library AnimateImages;

uses
  SysUtils,
  Classes;

{$R *.res}
{$R IMAGES.res}

begin
end.
0
 
sal1150Author Commented:
thanks SHane.

I makke some change in your code.
It is now working good.
again thanku and I will increase the points to 450.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 15
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now