ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Round corners as image effect?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

924 Posts

Posted - May 21 2013 :  16:09:37  Show Profile  Reply
Hi! Is it possible to get Round Corners as an image effect? Of course the cut off parts should be transparent.

w2m

USA
1990 Posts

Posted - May 21 2013 :  16:18:04  Show Profile  Reply
TImageEnProc.RoundImage

Declaration

procedure RoundImage(RoundWidth, RoundHeight:integer);

Description

Makes corners rounded.
RoundWidth and RoundHeight specify the round size.

Example
ImageEnView1.Proc.RoundImage(100, 100);

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

PeterPanino

924 Posts

Posted - May 21 2013 :  16:44:23  Show Profile  Reply
Thanks for the hint!

1. However, the first time I run this command, my screen became black and started to flash and flicker for a few seconds, my Chrome browser crashed, and I got this error message box:



The next times I run the program nothing happened.

2. The round corners are somewhat jagged:



Isn't there something to make them more smooth, e.g. antialiasing?

EDIT:

3. Also, when I set BackgroundStyle to iebsSoftShadow, then the shadow does not follow the round corners (which it should do):



So how can I get nice and smooth round corners where the soft shadow follows the round corners?
Go to Top of Page

w2m

USA
1990 Posts

Posted - May 22 2013 :  07:00:24  Show Profile  Reply
procedure TForm1.Button1Click(Sender: TObject);
var
  iRGB: TRGB;
begin
  Screen.Cursor := crHourGlass;
  try
    ImageEnView1.Proc.SaveUndoCaptioned('Round ' + IntToStr(ImageEnView1.Proc.UndoCount));
    Undo1.Hint := 'Round ' + IntToStr(ImageEnView1.Proc.UndoCount);
    ImageEnView1.Proc.RoundImage(20, 20);
    ImageEnView1.IO.Params.BitsPerSample := 8;
    ImageEnView1.IO.Params.SamplesPerPixel := 4;
    iRGB := ImageEnView1.IEBitmap.Pixels[0, ImageEnView1.IEBitmap.Height - 1];
    ImageEnView1.Proc.SetTransparentColors(iRGB, iRGB, 0);
    ImageEnView1.Proc.AddSoftShadow(4, 4, 4, True, clBlack, 100);
    Undo1.Enabled := ImageEnView1.Proc.CanUndo;
    ImageEnView1.Bitmap.Modified := True;
    ImageEnView1.Update;
    Undo1.Enabled := ImageEnView1.Proc.CanUndo;
  finally
    Screen.Cursor := crDefault;
  end;
end;

Unfortunately there is no overloaded RoundImage that uses antialiasing.

158.83 KB
William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  07:53:37  Show Profile  Reply
Hi William, thanks a lot for the code which works well with TImageEnView!

However, in my specific project I cannot use TImageEnView (because it does not have a Transparent property which I need for something other). So I have to use TImageEnIO and TImageEnProc with TImage instead. Unfortunately, I was not successful in transforming the code for the use of TImageEnIO and TImageEnProc with TImage. Is it possible to use your code with TImageEnIO and TImageEnProc with TImage? Also, I didn't find any "Undo" class (you've used "Undo1" object in your code).
Go to Top of Page

w2m

USA
1990 Posts

Posted - May 22 2013 :  08:53:03  Show Profile  Reply
Use ImageEnIO and ImageEnProc with attached TImage:
ImageEnProc1.AttachedTImage := Image1;
ImageEnIO1.AttachedTImage := Image1;

ImageEnProc1.SaveUndoCaptioned('Round ' + IntToStr(ImageEnProc1.UndoCount));
Undo1.Hint := 'Round ' + IntToStr(ImageEnProc1.UndoCount);

procedure TForm1.Undo1Click(Sender: TObject);
begin
  ImageEnProc1.Undo();
  ImageEnProc1.ClearUndo;
  if not ImageEnProc1.CanUndo then
    Undo1.Hint := '';
  Undo1.Enabled := ImageEnProc1.CanUndo;
end;

Unfortunately I can not get RoundImage or AddSoftShadow to function correctly with TImage. I suspect the reason these two functions do not work is because of the way Timage handles transparency.

As a work-around you could use ImageEnView to make the rounded bitmap and then assign the bitmap to TImage. It works:
procedure TForm1.Button3Click(Sender: TObject);
{ Round the corners of a bitmap and add a transparent shadow with ImageEnView, and assign the result to TImage. }
var
  iImageEnView: TImageEnView;
begin
  Screen.Cursor := crHourGlass;
  try
    ImageEnProc1.SaveUndoCaptioned('Round ' + IntToStr(ImageEnProc1.UndoCount));
    Undo1.Hint := 'Round ' + IntToStr(ImageEnProc1.UndoCount);
    iImageEnView := TImageEnView.Create(nil);
    try
      iImageEnView.Bitmap.Assign(Image1.Picture.Graphic);
      iImageEnView.Proc.RoundImage(20, 20);
      iImageEnView.Proc.AddSoftShadow(4, 4, 4, True, clBlack, 100);
      iImageEnView.RemoveAlphaChannel(true);
      Image1.Picture.Graphic.Assign(iImageEnView.Bitmap);
      Image1.Update;
      Undo1.Enabled := ImageEnProc1.CanUndo;
    finally
      iImageEnView.Free;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;

Screenshot of TImage:

146.91 KB
William Miller
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  09:35:00  Show Profile  Reply
Hi William!

When assigning between the two, it does not work with TImage at all. However it partially works with a TJvSpecialImage - the corners are rounded, but instead of a soft shadow I get a black frame:



I have Delphi XE2.
Go to Top of Page

w2m

USA
1990 Posts

Posted - May 22 2013 :  09:39:07  Show Profile  Reply
All I can say is it works perfectly here with Delphi 2010 and the latest version of ImageEn. I have Image1.Transparent set to True here. The screen shot was of a TImage not ImageEnView. Try changing the transparent property and let me if it works then.

Is your image 24-bit?

William Miller
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  09:49:12  Show Profile  Reply
Hi William, there must have been a mismatch with the code before. I copied your code again, and now it works perfectly with TJvSpecialImage! (No more black frame, but nice soft shadow). However it does not work at all with TImage here - Transparent property is set to True!
Go to Top of Page

w2m

USA
1990 Posts

Posted - May 22 2013 :  09:57:17  Show Profile  Reply
Your forms transparentcolor setting and transparent color property value properties may be interfering with TImage. Because TImage.Transprent property is true.

I seldom use TImage because it does not have rubberbanding and does not handle transparency very well. I have no idea of why mine works but yours does not.

William Miller
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  10:03:33  Show Profile  Reply
Form1.TransparentColor is set to False here. But it should at least work with the round corners.
However, thank you very much! It works well with TJvSpecialImage and that's perfect for me. Thank you!
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  10:10:17  Show Profile  Reply
Heureka! Now it DOES work with TImage, but you have to change
Image1.Update;
to:
Image1.Repaint;

Thank you!!!
Go to Top of Page

PeterPanino

924 Posts

Posted - May 22 2013 :  11:19:11  Show Profile  Reply
However, there is still something missing: When assigning from iImageEnView to Image1 at the end, the background of iImageEnView is copied too! Here in this example I've set the background of iImageEnView to clFuchsia:



iImageEnView.Background := clFuchsia;

But it should be alpha-transparent instead!

So how can I set the background around the image and underneath the soft-shadow alpha-transparent?
Go to Top of Page

w2m

USA
1990 Posts

Posted - May 22 2013 :  13:08:41  Show Profile  Reply
Send me your email address where I can attach my simple demo in a zip file.

What version of ImageEn are you using?

I do not get the background color here at all. The background is transparent here.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: