Board index » delphi » Imagelist doesn't paint on TImage?

Imagelist doesn't paint on TImage?

A code snippet follows.  In this form, I have one TImage with a bitmap
already loaded into it.  When I press a button, I try to have the
Imagelist first image to draw itself on the form and the TImage.  The
form one shows up, the TImage one does not.

What am I missing?

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
imagelist1.draw( form1.canvas,0,0,0);
imagelist1.draw( image1.canvas,0,0,0);
end;

end.

  tiede.vcf
< 1K Download
 

Re:Imagelist doesn't paint on TImage?


try Image1.refresh;

But your example works for me without refreshing though.

Kerstin

Mark Tiede schrieb:

Quote

> A code snippet follows.  In this form, I have one TImage with a bitmap
> already loaded into it.  When I press a button, I try to have the
> Imagelist first image to draw itself on the form and the TImage.  The
> form one shows up, the TImage one does not.

> What am I missing?

> unit Unit1;

> interface

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

> type
>   TForm1 = class(TForm)
>     ImageList1: TImageList;
>     Button1: TButton;
>     Image1: TImage;
>     procedure Button1Click(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> var
>   Form1: TForm1;

> implementation

> {$R *.DFM}

> procedure TForm1.Button1Click(Sender: TObject);
> begin
> imagelist1.draw( form1.canvas,0,0,0);
> imagelist1.draw( image1.canvas,0,0,0);
> end;

> end.

Re:Imagelist doesn't paint on TImage?


Quote
On Sat, 15 Jan 2000 14:23:41 -0500, Mark Tiede <ti...@ibm.net> wrote:
>A code snippet follows.  In this form, I have one TImage with a bitmap
>already loaded into it.  When I press a button, I try to have the
>Imagelist first image to draw itself on the form and the TImage.  The
>form one shows up, the TImage one does not.

>What am I missing?

I can't duplicate that behavior; the image from the image list shows
up just fine on both canvases. What kind of image is it (bitmap, icon,
etc.)?

-Steve

Re:Imagelist doesn't paint on TImage?


Steve,

   As I originally said, the TImage has a bitmap in it.

  Since neither you nor Kerstin can duplicate the problem, perhaps it is a
problem with my Win95 software.  I recently installed some software that
was targeted for an NT machine just to take a look at some driver software
and its help system.  I had really forgotten that it was for NT.  Since
that install, I have had a couple of problems with Delphi.  Now, quite
often when I do a "program reset" during debugging, I get a timeout message
on trying to stop a thread.  If I abort (or take any of the 3 choices given
me), I can no longer recompile to the EXE.  I must reboot to work again.  A
real nuisance.

  So this imagelist behaviour may be a result of the same thing.  I have a
notion that the install replaced some system files.

   Thanks for looking into it.

And thanks to Kerstin too.

  tiede.vcf
< 1K Download

Re:Imagelist doesn't paint on TImage?


Kerstin,

   Image1.Refresh would redraw the image, but I am separately painting the
imagelist, so if the imagelist drew in the first place, then the refresh
would paint right over it.

   Read my reply to Steve.

   Thanks for trying it and letting me know it works for you.

  tiede.vcf
< 1K Download

Re:Imagelist doesn't paint on TImage?


Hi Mark,

I have to confess that I've overseen that you already had an bitmap loaded
in your Image. But have you actually tried the Refresh? Whithout it it doesn't
work for me too but with Refresh it works. As soon as you load a bitmap into
an Image the Image.Canvas represents the Bitmap.Canvas, that means when you
Draw on the Image.Canvas you Draw on the Bitmap.Canvas.

HTH
Kerstin

Mark Tiede schrieb:

Quote

> Kerstin,

>    Image1.Refresh would redraw the image, but I am separately painting the
> imagelist, so if the imagelist drew in the first place, then the refresh
> would paint right over it.

>    Read my reply to Steve.

>    Thanks for trying it and letting me know it works for you.

Re:Imagelist doesn't paint on TImage?


Quote
On Sun, 16 Jan 2000 09:19:01 -0500, Mark Tiede <ti...@ibm.net> wrote:
>   Image1.Refresh would redraw the image, but I am separately painting the
>imagelist, so if the imagelist drew in the first place, then the refresh
>would paint right over it.

I don't understand what you're saying here. You _do_ need to refresh
the TImage whenever you make any changes "behind its back," so to
speak. Drawing on it from an image list qualifies as "behind its
back," since the image list doesn't know anything about Delphi
canvases, and uses API functions to do its work.

-Steve

Re:Imagelist doesn't paint on TImage?


Steve,

   I see a bit more clearly now.  thanks for the follow up.  Yes, I think I
must do a refresh or repaint to get it to show up.  I thought if I drew on the
canvas and then told the image to refresh, it would just repaint its canvas
from scratch and I would lose what I had added.

   I have tried things at work (Windows NT) and they worked as they had at
home.  That means my system must not be terribly screwed up, as I feared :-)

   Now here is my current problem or the path to "transparency".  I have made a
TCustomControl descendent.  I overrode the Create, Destroy and Paint methods.
Here is the code:

   constructor TDripBag.Create( AnOwner : TComponent );
      var
         Bitmap : graphics.TBitmap;
      begin
      inherited;

      Bitmap := graphics.TBitmap.Create;
      try
         Bitmap.LoadFromResourceName( HInstance,  'DRIPBAG' );
         ImageList := TImageList.CreateSize( Bitmap.Width,
                                             Bitmap.Height );
         ImageList.BkColor      := clNone;
         ImageList.BlendColor   := clNone;
         ImageList.DrawingStyle := dsTransparent;
         ImageList.Masked       := True;
         ImageList.AddMasked( Bitmap, Bitmap.Canvas.Pixels[0,0] );
      finally
         Bitmap.Free;
         end;

      Hint := 'Drip Bag Object|Drip Bag Object';

      SetBounds( 0, 0, ImageList.Width, ImageList.Height );

      ComponentID := '';
      Position    := '';
      Notes       := '';

      end;

   destructor TDripBag.Destroy;
      begin
      if ImageList <> nil then ImageList.Free;

      inherited;
      end;

   procedure TDripBag.Paint;
      begin
      ImageList.Draw( Canvas, 0, 0, 0 );
      end;

When I dynamically created one of these, the tranparency seemed at first to
work.  When I placed the object on the form and changed the color of the form,
the objects transparent parts showed the form color giving the transparent
effect.

Now I placed a scrollbox on the form and an image in the scrollbox.  When my
object paints, it still paints the panels color in the transparent areas.  I
wanted to be able to put the object over the image and see the image underneath
the object.  I end up instead with a rectangular box in the form color with my
object drawn on it.  I fooled around with a variety of guesses, but no joy.

Any suggestions?

  mtiede.vcf
< 1K Download

Re:Imagelist doesn't paint on TImage?


On Mon, 17 Jan 2000 15:18:16 -0500, "Mark L. Tiede"

Quote
<mti...@mjwcorp.com> wrote:
>Now I placed a scrollbox on the form and an image in the scrollbox.  When my
>object paints, it still paints the panels color in the transparent areas.  I
>wanted to be able to put the object over the image and see the image underneath
>the object.  I end up instead with a rectangular box in the form color with my
>object drawn on it.  I fooled around with a variety of guesses, but no joy.

The chances of successfully creating a partially transparent windowed
control are not utterly zero. However, they are so close to zero that
you can't tell the difference. If at all possible, you should derive
your component from TGraphicControl rather than TCustomControl.

-Steve

Re:Imagelist doesn't paint on TImage?


Steve,

   I changed from TCustomControl ancestor to TImage.  I set the Transparent to True
and changed the TScrollBox.DoubleBuffered := True.  I think most things are fine
now.  The image transparency seems fine and I can drag the images around with very
little flicker and the different "z-order" levels let the TImages move under or over
each other the way I expected.

   Now my only problem is that I wanted to drag the image out of the scrollbox and
over a trashcan image to delete it.  The scrollbox just scrolls my image location
further and further to the right increasing the scrollbar on the scroll box.

   Any suggestions for being able to drag the image out of the scrollbox?  I tried
hooking the OnDragOver on the trashcan image, but it never gets invoked even when
the cursor is over it.  I tried 2 techniques.  One was with a
SetCapture-ReleaseCapture and the other was with TImageList drag methods.

  mtiede.vcf
< 1K Download

Re:Imagelist doesn't paint on TImage?


On Tue, 18 Jan 2000 14:10:23 -0500, "Mark L. Tiede"

Quote
<mti...@mjwcorp.com> wrote:
> Any suggestions for being able to drag the image out of the scrollbox?

I can't think of anything offhand if you want to be able to use a
standard TScrollBox. If you're willing to customize the scroll box,
you can make it do pretty much whatever you want, of course.

-Steve

Other Threads