Results 1 to 6 of 6

Thread: Cannot Copy Image from one TImage to another

  1. #1

    Cannot Copy Image from one TImage to another

    Im writing my first game in Delphi (with DelphiX). I have some experience with Pascal, and delphi. The game is tile based, and the images are stored in TDXImageList. I am animating each tile, simply by incrementing a FRAME variable, used when calling Tile.items[whatever].draw(...,FRAME);

    This is working fine, however, the graphics have to be put into the ImageList at designtime. By looking through previous posts, I have managed to put together some additional features, that allow the addition of BMP files to the Imagelist (Thanks everyone).
    The problem I am having now is with TImage. I want the user to be able to load 6 BMP files, into 6 TImages, then press a button, and those six images, get turned into one image, and stored into my ImageList. I can get my 6 images into their TImage, and i can save a TImage to the imagelist, however, I cannot get 6 images to go onto one TImage. I have tried the copyrect command, I have tried doing a pixel to pixel copy, i have tried drawing my six images to a surface, but was unable to get them into the image list. I have spent the whold day on this, trying every possible way i can think of, but none works. I keep getting the error that the image does not contain a bitmap. Or the TImage on the form used to display the image goes blank, or an error regarding surfaces. Unfortunatly I have been angrily overwriting the code in question, so i dont have all the variations of my code. The ideal way i can see would be to to use the old copyrect, but that only left me with a blank TImage on the form.

    Hope someone can Help!!

  2. #2

    Cannot Copy Image from one TImage to another

    I believe canvas.release causes the problem.

    Code:
    var
      Form1: TForm1;
      Surface : TDirectDrawSurface;
      NewSurface : TDirectDrawSurface;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
    begin
      Form1.DXDraw1.Surface.Draw(0,0, Surface.ClientRect, Surface, false);
      Form1.DXDraw1.Surface.Draw(100, 300, NewSurface.ClientRect, NewSurface, false);
    
      Form1.DXDraw1.Flip;
    end;
    
    procedure copyTOImagelist();
    begin
        newSurface.Canvas.CopyRect(rect(0,0,100,100), surface.Canvas, rect(150,50,250,150) );
        newSurface.Canvas.CopyRect(rect(100,0,200,100), surface.Canvas, rect(150,350,250,450) );
        newSurface.Canvas.Release;
    end;
    
    procedure TForm1.DXDraw1Initialize(Sender: TObject);
    begin
      Surface := TDirectDrawSurface.Create(DXDraw1.DDraw);
      Surface.LoadFromGraphic(Form1.DXImagelist1.items.items[0].picture.graphic);
    
      NewSurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
      NewSurface.SetSize(200,100); //set default size;
      NewSurface.Fill(0);  //set default color;
    end;
    
    procedure TForm1.DXDraw1Finalize(Sender: TObject);
    begin
      Surface.free;
      NewSurface.free;
    end;
    
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      copyTOImagelist
    end;
    
    end.
    The above code creates 2 surfaces. The first loads an image at startup. If, at runtime the user presses the button it will load two smaller portions of the first surface into the second surface.

    After that you can either save it to a file or load it into another list.

  3. #3

    Cannot Copy Image from one TImage to another

    Thanks for quick reply, "Release" eh? thanks, but this has only helped with surface canvas,

    my main problem hopefully will be clearer if you look at this screenshot



    each item in my imagelist, is divided into six (pattern?) tiles, i want the user to be able to load six BMP images (the working load procedure is in the onclick events for the six), to make one entryinto the imagelist, but I cannot find a way to sucessfully make one 384*32 image from the indivigual images. I always end up with the upper image, being blank (transparant, as the green form shows through, like when the picture property for timage is not been set). Someone else must have made an app similar to this for editing ImageLists?

    (ps sorry the screen shot shows only a static grass tile :? )

    This image was made as one wide file, but i want to be able to load the tiles into the imagelist, one-by-one

    is it possible?

  4. #4

    Cannot Copy Image from one TImage to another

    I'm despite your answer still not sure what you mean then.

    I lose you at 'I always end up with the upper image, being blank'. What do you mean by that?

    In my samplecode I copy parts of a surface and place them next to eachother (they might as well have been whole images). I'm not sure why this doesn't answer your question, when you say
    Quote Originally Posted by BaronBigman
    but I cannot find a way to sucessfully make one 384*32 image from the indivigual images.

  5. #5

    Cannot Copy Image from one TImage to another

    If you could post up some sample code or a sample project that doesn't work there are plenty of us here that could look at it and see if we can spot your problem. It also helps to have a prototype that shows the desired response (simple as an image showing before change and after). Sounds like your trying to build a tile joiner.

  6. #6

    Cannot Copy Image from one TImage to another

    Hi thanks,

    I was making a tile joiner! I dont have constant internet access, so its been a while. I decided to re-write the app, so i could make a nice source to show you, and it seems that its working now! Grr. This app works, lol, I think im going to be crazy! Anyway, I will continue to build this back into my tile manager for my world builder, and perhaps the original problem, that i cant store into the imagelist will return. This is the code that took 5mins to write, and it works, any suggestions to improve wellcomed (ie can you make array of image objects from the "additional" toolbar? so i could do image[x] rather than access each timage indivigual?)

    Thanks for your help people, when the game is finished, i will post some links on the site

    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, jpeg, ExtDlgs, StdCtrls, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Image1: TImage;
        Image2: TImage;
        Image3: TImage;
        Image4: TImage;
        Image5: TImage;
        Image6: TImage;
        Image7: TImage;
        Button1: TButton;
        OpnPic1: TOpenPictureDialog;
        procedure Image6Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Image5Click(Sender: TObject);
        procedure Image4Click(Sender: TObject);
        procedure Image3Click(Sender: TObject);
        procedure Image2Click(Sender: TObject);
        procedure Image1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Image1Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image1.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Image2Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image2.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Image3Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image3.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Image4Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image4.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Image5Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image5.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Image6Click(Sender: TObject);
    begin
     if opnpic1.execute then
      image6.Picture.LoadFromFile(opnpic1.FileName);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
     image7.Canvas.CopyRect(rect(0,0,64,32),image1.Canvas,rect(0,0,64,32));
     image7.Canvas.CopyRect(rect(64,0,128,32),image2.Canvas,rect(0,0,64,32));
     image7.Canvas.CopyRect(rect(128,0,192,32),image3.Canvas,rect(0,0,64,32));
     image7.Canvas.CopyRect(rect(192,0,256,32),image4.Canvas,rect(0,0,64,32));
     image7.Canvas.CopyRect(rect(256,0,320,32),image5.Canvas,rect(0,0,64,32));
     image7.Canvas.CopyRect(rect(320,0,384,32),image6.Canvas,rect(0,0,64,32));
    end;
    
    end.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •