Solved

Image with round corner - Graphics32

Posted on 2010-09-14
3
2,278 Views
Last Modified: 2013-11-22
I would like to know the best way to create smooth round corners in one image (with different radius; from small up to half width/height) and make this corner transparent.

I found one procedure to draw a rectangle with rounded corners from Kieran Foster (December 7th, 2007), but as explained I need to cut the corners from image in a way that they are smooth and with a rounded shape. The part removed to create the round corner should be transparent.
Thx
0
Comment
Question by:andrefm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 33671219
On which kind of canvas do you want to draw ?
In a Timage ? a custom component ? Maybe the form itself ?

I ask this because of the "transparency" which is not achieved the same way in all cases. Forms shapes, for example, can have transparent zones thanks to "regions" that are cut out from the normal form rectangle.
For images, it is merely a specific color that is stated as the transparent color, so it is just a matter of painting the outside of the rounded corner with that color.
0
 
LVL 25

Accepted Solution

by:
epasquier earned 500 total points
ID: 33671535
Here is an example with TImage :
put a TImage and trackbar. The trackbar have a Min property of 0, and a Max of 100. It will change the percentage of the width/height taken by the rounded corners. 0 = perfect rectangle, 100=ellipse

Add the following code to draw a rounded rectangle, fill it with white, and the corners are transparent (filled with a constant color that is not likely going to be used for the drawing.
To better view the transparency, add a Timage with a loaded image and set it behind the first TImage


type
  TForm1 = class(TForm)
    trckbr1: TTrackBar;
    img1: TImage;
    img2: TImage;
    procedure FormCreate(Sender: TObject);
    procedure trckbr1Change(Sender: TObject);
  private
    procedure PaintCorner;
  public

var
  Form1: TForm1;

implementation

Const
 clTransp=$111213; // transparent color

procedure TForm1.FormCreate(Sender: TObject);
begin
 img1.Picture.Bitmap:=TBitmap.Create;
 img1.Picture.Bitmap.Width:=img1.Width;
 img1.Picture.Bitmap.Height:=img1.Height;
 img1.Picture.Bitmap.TransparentColor:=clTransp;
 img1.Transparent:=True;
 PaintCorner;
end;


procedure TForm1.trckbr1Change(Sender: TObject);
begin
 PaintCorner;
end;

procedure TForm1.PaintCorner;
Var
 W,H,RW,RH:Integer;
begin
 With img1.Picture.Bitmap,Canvas do
  begin
   Pen.Color:=clRed;
   Brush.Color:=clTransp;
   FillRect(ClipRect);
   RW:=Width-1;
   RH:=Height-1;
   W:=Width*trckbr1.Position Div 200;
   H:=Height*trckbr1.Position Div 200;
   Arc(0,0,2*W,2*H,W,0,0,H+1);
   MoveTo(W,0);
   LineTo(RW-W,0);
   Arc(RW,0,RW-2*W,2*H,RW,H,RW-W-1,0);
   MoveTo(RW,H);
   LineTo(RW,RH-H);
   Arc(RW,RH-2*H,RW-2*W,RH,RW-W,RH,RW,RH-H-1);
   MoveTo(W,RH);
   LineTo(RW-W,RH);
   Arc(0,RH,2*W,RH-2*H,0,RH-H,W+2,RH);
   MoveTo(0,H);
   LineTo(0,RH-H);
   Brush.Color:=clWhite;
   FloodFill(RW Div 2, RH Div 2,clRed, fsBorder);
  end;
end;

end.

Open in new window

0
 

Author Closing Comment

by:andrefm
ID: 33688675
Expected solution using Graphics32, but could easily adapt.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 154
oracle global variables 4 80
Delphi and Access based Enumeration 9 90
Delphi: barcode reading on android platform 1 101
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question