ImagePanels

This unit replaces the obsolete BitmapPanels unit.

The TPanel component is no longer subclassed, it's now the ancestor of two new components: TImagePanel and TBitmapPanel.

The main differences between the old subclassed TPanel and the new TBitmapPanel are:


This unit provides two powerful image viewer components - TImagePanel and TBitmapPanel.

TImagePanel:
This component displays images and drawings of almost any size. Using its OnDrawImage event, it renders only the visible portion of the image at one time. This component can display vector drawings (SVG images) scaled to any size; and thousands of thumbnail images, as if they were a single scrolled image. Other features include:

The key OnDrawImage event passes three parameters: the destination TCanvas; the unscaled clip bounds in the source image; and the drawing bounds on the destination canvas. It's then up to the component user to render the specified clip of the source image into the specified region on the destination canvas. The component is completely agnostic to the nature of the source image.

Methods Properties Events
BitmapToClient
ClearBitmap
ClientToBitmap
GetInnerClientRect
AllowScroll
AllowZoom
FocusedColor
InnerMargin
Offset
Scale
ScaleMax
ScaleMin
ScalingCursor
ScrollButtonColor
ScrollButtonColorHot
ScrollButtonsVisible
OnDrawImage
OnKeyDown
OnKeyUp
OnResizing
OnScrolling


TBitmapPanel:

This component is a direct descendant of TImagePanel and displays a single Bitmap. And conveniently, the user doesn't need to implement TImagePanel's OnDrawImage event. Also:

Additional methods, properties and events:

Methods Properties Events
CopyToClipboard
PasteFromClipboard
Bitmap
CopyPasteEnabled
FileDropEnabled
OnFileDrop
OnPaste





  uses                    
    Forms, ExtCtrls, ImagePanels,  
    Image32, Image32_PNG;

  ....
  
  procedure TForm1.FormCreate(Sender: TObject);
  var 
    img: TImage32;
  begin
    //enable 32bit alpha transparency
    ImagePanel1.Bitmap.PixelFormat := pf32bit;

    //Load an image using a TImage32 object 
    //and display it in ImagePanel1
    img := TImage32.create;
    try
      img.LoadFromResource('MYIMAGE', 'PNG');    
      ImagePanel1.Bitmap.SetSize(img.Width, img.Height);
      img.CopyToDC(ImagePanel1.Bitmap.Canvas.Handle);
    finally
      img.free;
    end;
    
  end;
      

TImagePanel and TBitmapPanel keyboard actions:

unless its TabStop property = false
0 (zero) Scales the image to best fit
1..9 Scales the image 1 to 9 times normal
[shift] + 1..9 Scales the image 0.1 to 0.9 times normal
arrow keys (◀▲▼▶) normal scrolling
[shift] + arrow keys accelerated (5 times normal) scrolling
[ctrl]+▲ ; [ctrl]+▼ zoom in and zoom out respectively



See Also

Home, OnFileDrop, OnPaste, CopyToClipboard, PasteFromClipboard, Bitmap, CopyPasteEnabled, FileDropEnabled, OnDrawImage, OnKeyDown, OnKeyUp, OnResizing, OnScrolling, BitmapToClient, ClearBitmap, ClientToBitmap, GetInnerClientRect, AllowScroll, AllowZoom, FocusedColor, InnerMargin, Offset, Scale, ScaleMax, ScaleMin, ScalingCursor, ScrollButtonColor, ScrollButtonColorHot, ScrollButtonsVisible