Transparent image control with resampling in Delphi

I have a form with a background image (written on the form in Form1.Repaint).

I'm looking for: A transparent image control that can smoothly resize (overfulfill) an uploaded image.

(I need it to be transparent, because the background image of the form must be visible)

What I tried:

  • Standard TImage: It is transparent but does not repeat.

  • Graphics32 / Image32: Reacts beautifully but not transparently.

    I have several hours on the Internet for corrections or workarounds, but without a lot of solutions. This is not because the image uploaded to Image32 is transparent, but instead the background color of the control is still white (white = the color property of the Image32 control and setting it to clNone does not work). It is apparently designed

  • GR32ex (the GR32 extension component package), which supposedly adds the Transparent property, however it has not been updated for many years, and I cannot install it. It throws gazillion errors on Delphi 2010 and Graphics32 version 1.9.

Can anyone think of a solution or a workaround? All I want is control with transparency and resampling.

Thanks!

+6
source share
1 answer

I am surprised that TImage32 does not make transparency. Are you really sure this is so?

In any case, if so, I would combine TImage transparency TImage with TImage re-fetch TBitmap32 to build the solution this way. Save the original image in a TBitmap32 instance. Whenever you need to load it into the TImage component, for example, when recalibrating, use TBitmap32 to perform an override in memory and load the image with dimensions.

In fact, if you already draw the background, yourself, why not draw the image yourself and just not cope with image management?

Update 1:. Websearch shows an easy way to make TImage32 transparent: http://graphics32.org/news/newsgroups.php?art_group=graphics32.general&article_id=9505

Update 2:. The above link is now dead, and newsgroups can only be accessed through NNTP. I can't be 100% sure, but I think the linked post was Michael Jaralabos and contained the following file:

 unit GR32_ImageEx; // Transparent TImage32 by Michael Haralabos interface uses Windows, Messages, Classes, GR32_Image, GR32; type TImage32Ex = class(TImage32) private FTransparent: Boolean; procedure SetTransparent(const Value: Boolean); public procedure ExecClearBackgnd(Dest: TBitmap32; StageNum: Integer); override; published property Enabled; property Transparent: Boolean read FTransparent write SetTransparent; end; procedure Register; implementation procedure TImage32Ex.ExecClearBackgnd(Dest: TBitmap32; StageNum: Integer); var P: TPoint; SaveIndex: Integer; begin if FTransparent and Assigned(Parent) and not (Assigned(Bitmap) and (BitmapAlign = baTile)) then begin SaveIndex := SaveDC(Dest.Handle); GetViewportOrgEx(Dest.Handle, P); SetViewportOrgEx(Dest.Handle, PX - Left, PY - Top, nil); IntersectClipRect(Dest.Handle, 0, 0, Parent.ClientWidth, Parent.ClientHeight); Parent.Perform(WM_ERASEBKGND, Dest.Handle, 0); Parent.Perform(WM_PAINT, Dest.Handle, 0); RestoreDC(Dest.Handle, SaveIndex); end else inherited; end; procedure TImage32Ex.SetTransparent(const Value: Boolean); begin if FTransparent <> Value then begin FTransparent := Value; Invalidate; end; end; procedure Register; begin RegisterComponents('Graphics32', [TImage32Ex]); end; end. 

Another topic here says that it could be what the dead link was talking about now: Delphi TImage32 - how to make a component invisible if the image is not loaded?

+5
source

Source: https://habr.com/ru/post/918940/


All Articles