Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 858597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:33:48+00:00 2026-05-15T08:33:48+00:00

I am working with delphi. I have TImage, to which I assign a bitmap.

  • 0

I am working with delphi. I have TImage, to which I assign a bitmap.

imgmain.Picture.Bitmap := bmpMain;
imgmain.Picture.Bitmap.PixelFormat := pf24bit;

imgmain is object of TImage and bmpMain is object of TBitmap

I want to zoom my image. I have one trackbar on my form and as I click on trackbar the image should get zoom. What should I do?
Thank You.

Edit :
I found some solution at here It works but it cut my image.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:33:48+00:00Added an answer on May 15, 2026 at 8:33 am

    The code you refer to sets up a transformation from one coordinate space to another, I didn’t notice anything that would cut/crop your image there. However, instead of having an inversely proportional zoom factor I’d rather have, easy to understand, linear scaling. Also, I see no reason switching map modes depending on the scaling factor, I would modify the SetCanvasZoomFactor like this;

    procedure SetCanvasZoomPercent(Canvas: TCanvas; AZoomPercent: Integer);
    begin
      SetMapMode(Canvas.Handle, MM_ISOTROPIC);
      SetWindowExtEx(Canvas.Handle, 100, 100, nil);
      SetViewportExtEx(Canvas.Handle, AZoomPercent, AZoomPercent, nil);
    end;
    

    A simplified (no error checking) working example with a bitmap loaded to a TImage, scaled via a TrackBar could be like the below. Note that the above function is inlined in the TrackBar’s OnChange event.

    type
      TForm1 = class(TForm)
        imgmain: TImage;
        TrackBar1: TTrackBar;
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure TrackBar1Change(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        bmpmain: TBitmap;
      [..]
    
    [...]
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      bmpmain := TBitmap.Create;
      bmpmain.LoadFromFile(ExtractFilePath('samplebitmap.bmp');
      bmpmain.PixelFormat := pf32bit; // No significance, just seems faster here than pf24bit
    
      TrackBar1.Min := 10;
      TrackBar1.Max := 200;
      TrackBar1.Frequency := 10;
      TrackBar1.PageSize := 10;
      TrackBar1.Position := 100; // Fires OnChange
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
     bmpmain.Free;
    end;
    
    procedure TForm1.TrackBar1Change(Sender: TObject);
    var
      Zoom, x, y: Integer;
    begin
      Zoom := TrackBar1.Position;
      if not (Visible or (Zoom = 100)) or (Zoom = 0) then
        Exit;
    
      SetMapMode(imgmain.Canvas.Handle, MM_ISOTROPIC);
      SetWindowExtEx(imgmain.Canvas.Handle, 100, 100, nil);
      SetViewportExtEx(imgmain.Canvas.Handle, Zoom, Zoom, nil);
      x := imgmain.Width * 50 div Zoom - bmpmain.Width div 2;
      y := imgmain.Height * 50 div Zoom - bmpmain.Height div 2;
      imgmain.Canvas.Draw(x, y, bmpmain);
      if (x > 0) or (y > 0) then begin
        imgmain.Canvas.Brush.Color := clWhite;
        ExcludeClipRect(imgmain.Canvas.Handle, x, y, x + bmpmain.Width, y + bmpmain.Height);
        imgmain.Canvas.FillRect(imgmain.Canvas.ClipRect);
      end;
    
      Label1.Caption := 'Zoom: ' + IntToStr(TrackBar1.Position) + '%';
    end;
    

    edit: same code with a TImage in a ScrollBox;

    type
      TForm1 = class(TForm)
        TrackBar1: TTrackBar;
        Label1: TLabel;
        ScrollBox1: TScrollBox;
        imgmain: TImage;
        procedure FormCreate(Sender: TObject);
        procedure TrackBar1Change(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        bmpmain: TBitmap;
      [...]
    [...]
    
    const
      FULLSCALE = 100;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      imgmain.Left := 0;
      imgmain.Top := 0;
    
      bmpmain := TBitmap.Create;
      bmpmain.LoadFromFile(ExtractFilePath(Application.ExeName) + '610x.bmp');
      bmpmain.PixelFormat := pf32bit;
    
      TrackBar1.Min := FULLSCALE div 10;   // %10
      TrackBar1.Max := FULLSCALE * 2;      // %200
      TrackBar1.PageSize := (TrackBar1.Max - TrackBar1.Min) div 19;
      TrackBar1.Frequency := TrackBar1.PageSize;
      TrackBar1.Position := FULLSCALE;
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      bmpmain.Free;
    end;
    
    procedure TForm1.TrackBar1Change(Sender: TObject);
    var
      Zoom: Integer;
    begin
      Zoom := TrackBar1.Position;
      if not (Visible or (Zoom = FULLSCALE)) or (Zoom = 0) then
        Exit;
    
      SetMapMode(imgmain.Canvas.Handle, MM_ISOTROPIC);
      SetWindowExtEx(imgmain.Canvas.Handle, FULLSCALE, FULLSCALE, nil);
      SetViewportExtEx(imgmain.Canvas.Handle, Zoom, Zoom, nil);
    
      imgmain.Width := Round(bmpmain.Width * Zoom / FULLSCALE);
      imgmain.Height := Round(bmpmain.Height * Zoom / FULLSCALE);
      if Assigned(imgmain.Picture.Graphic) then begin
        imgmain.Picture.Graphic.Width := imgmain.Width;
        imgmain.Picture.Graphic.Height := imgmain.Height;
      end;
      imgmain.Canvas.Draw(0, 0, bmpmain);
    
      Label1.Caption := 'Zoom: ' +
          IntToStr(Round(TrackBar1.Position / FULLSCALE * 100)) + '%';
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with delphi. I have one scroll box in which I am
I am working with delphi. I have an array of points which are continues
I've been working on a project in Delphi 7 where I wanted to have
Following up on this question, I'm working on a large Delphi 7 codebase which
Borland Developer Studio 2006, Delphi: I have a TOLEContainer object with AllowInPlace=False. When the
Working on a console application using Delphi 7, and have run into a problem.
Ok, this is a curly one. I'm working on some Delphi code that I
Working on a project at the moment and we have to implement soft deletion
Working with python interactively, it's sometimes necessary to display a result which is some
I have a web creation program which, when building a site, creates hundreds of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.