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

  • Home
  • SEARCH
  • 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 8943523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:47:34+00:00 2026-06-15T11:47:34+00:00

I’m trying to make a cropping tool that will look as follow: Original Image:

  • 0

I’m trying to make a cropping tool that will look as follow:

Original Image:

enter image description here

Crop tool – This is what I want:

enter image description here

Notice that the cropping area is showing the original colors, and around the colors are dim.


What I did is to place a TShape over my TImage with properties:

object Shape1: TShape
  Brush.Color = clSilver
  Pen.Mode = pmMask
  Pen.Style = psDot
end

I plan to use the TShape to make the re-sizing/coping control.
This is how it looks in Delphi:

enter image description here

As you can see, it does not looks good (colors palette looks dithered), but the main problem that I need the dim area to be around the crop area, not in the center. I have tried to cover the whole TImage with another TShpae, tried different Pen.Mode combinations but there are no good results, and I think my method/approach is bad.

Do you have any ideas on how to achieve the desired behavior?

  • 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-06-15T11:47:36+00:00Added an answer on June 15, 2026 at 11:47 am

    a little part is missing here, but should not be a problem to add…

    unit Unit3;
    // 20121108 by Thomas Wassermann
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, jpeg;
    
    type
      TForm3 = class(TForm)
        Image1: TImage;
        PaintBox1: TPaintBox;
        procedure FormCreate(Sender: TObject);
        procedure PaintBox1Paint(Sender: TObject);
        procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
        procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
      private
        { Private-Deklarationen }
        FDownPoint, FCurrentPoint: TPoint;
      public
        { Public-Deklarationen }
      end;
    
    var
      Form3: TForm3;
    
    implementation
    
    uses Math;
    {$R *.dfm}
    
    procedure TForm3.FormCreate(Sender: TObject);
    begin
      PaintBox1.BringToFront;
    end;
    
    type
      pRGBQuadArray = ^TRGBQuadArray;
      TRGBQuadArray = ARRAY [0 .. $EFFFFFF] OF TRGBQuad;
    
    Procedure SetAlpha(bmp: TBitMap; Alpha: Byte; R: TRect);
    var
      pscanLine32: pRGBQuadArray;
      i, j: Integer;
    begin
      bmp.PixelFormat := pf32Bit;
      bmp.HandleType := bmDIB;
      bmp.ignorepalette := true;
      bmp.alphaformat := afDefined;
      for i := 0 to bmp.Height - 1 do
      begin
        pscanLine32 := bmp.Scanline[i];
        for j := 0 to bmp.Width - 1 do
        begin
          if (j >= R.Left) and (j <= R.Right) and (i >= R.Top) and (i <= R.Bottom) then
          begin
            pscanLine32[j].rgbReserved := 0;
            pscanLine32[j].rgbBlue := 0;
            pscanLine32[j].rgbRed := 0;
            pscanLine32[j].rgbGreen := 0;
          end
          else
          begin
            pscanLine32[j].rgbReserved := Alpha;
            pscanLine32[j].rgbBlue := Alpha;
            pscanLine32[j].rgbRed := Alpha;
            pscanLine32[j].rgbGreen := Alpha;
          end;
        end;
      end;
    end;
    
    procedure TForm3.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      FDownPoint.X := X;
      FDownPoint.Y := Y;
      FCurrentPoint := FDownPoint;
      PaintBox1.Invalidate;
    end;
    
    procedure TForm3.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
      if ssLeft in Shift then
      begin
        FCurrentPoint.X := X;
        FCurrentPoint.Y := Y;
        PaintBox1.Invalidate;
      end;
    end;
    
    procedure TForm3.PaintBox1Paint(Sender: TObject);
    var
      bmp: TBitMap;
      SelRect: TRect;
    begin
      bmp := TBitMap.Create;
      try
        bmp.Width := PaintBox1.Width;
        bmp.Height := PaintBox1.Height;
        if (FCurrentPoint.X = FDownPoint.X) and (FCurrentPoint.Y = FDownPoint.Y) then
          SelRect := PaintBox1.BoundsRect
        else
        begin
          SelRect.Left := Min(FCurrentPoint.X, FDownPoint.X);
          SelRect.Top := Min(FCurrentPoint.Y, FDownPoint.Y);
          SelRect.Right := Max(FCurrentPoint.X, FDownPoint.X);
          SelRect.Bottom := Max(FCurrentPoint.Y, FDownPoint.Y);
        end;
        SetAlpha(bmp, 140, SelRect);
        PaintBox1.Canvas.Draw(0, 0, bmp);
      finally
        bmp.Free;
      end;
    end;
    
    end.
    

    The attempt on this solution is to use a overlying paintbox, same clientrect as the image, for all the drawing and selection. By using the coordinates generated by mouse/down/move a semitransparent bitmap is created, which is full transparent in the selected rect. After generation it’s painted on the paintbox. Further paintings could be done there e.g. frames, anchors, crosshair. Any user action would have to be caught in mousedown, depending of the selected part ,e.g. an anchor a sizing of the rect could be done.
    Usually I’d prefer GDI+ for requests like this, but as shown, no additional units are required. Source: http://www.bummisoft.de/download/transparenteauswahl.zip
    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm interested in microtypography issues on the web. I want a tool to fix:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.