Author |
Topic  |
|
PeterPanino
   
966 Posts |
Posted - May 21 2013 : 16:09:37
|
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 |
|
PeterPanino
   
966 Posts |
Posted - May 21 2013 : 16:44:23
|
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? |
 |
|
w2m
   
USA
1990 Posts |
Posted - May 22 2013 : 07:00:24
|
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 |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 07:53:37
|
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). |
 |
|
w2m
   
USA
1990 Posts |
Posted - May 22 2013 : 08:53:03
|
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 |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 09:35:00
|
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. |
 |
|
w2m
   
USA
1990 Posts |
Posted - May 22 2013 : 09:39:07
|
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 |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 09:49:12
|
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! |
 |
|
w2m
   
USA
1990 Posts |
Posted - May 22 2013 : 09:57:17
|
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 |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 10:03:33
|
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! |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 10:10:17
|
Heureka! Now it DOES work with TImage, but you have to change Image1.Update; to: Image1.Repaint;
Thank you!!! |
 |
|
PeterPanino
   
966 Posts |
Posted - May 22 2013 : 11:19:11
|
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? |
 |
|
w2m
   
USA
1990 Posts |
|
|
Topic  |
|