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
 Transparent Canvas?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

GregoryW

8 Posts

Posted - Nov 20 2012 :  23:06:28  Show Profile  Reply
Hello,

In ImageEnView I load a bitmap. Now i want to draw some shapes and fill them with a semi-transparent or slightly transparent color. Is it possible to do it?

When I draw a shape to ImageEnView I do the following:
with ImageEnView1.IEBitmap.Canvas do
  begin
    Pen.Width := 2;
    Pen.Color := PenColor;
    Brush.Color := FillColor;
    Brush.Style := bsSolid;
    Ellipse(x, y, x1, y1); // for example
  end;



How to fill shapes with semi-transparent color? Help please!

Greg

w2m

USA
1990 Posts

Posted - Nov 21 2012 :  09:37:19  Show Profile  Reply
// Paint Ellipse With GDI API
with ImageEnView1 do
begin
     Proc.UndoRect(XScr2Bmp(startX), YScr2Bmp(startY), XScr2Bmp(lastX), YScr2Bmp(lastY));
     IEBitmap.Canvas.Pen.Color := PaintColor.Color;
     if not Filled1.Checked then
     begin
       IEBitmap.Canvas.Brush.Style := bsClear;
       IEBitmap.Canvas.Ellipse(XScr2Bmp(startX), YScr2Bmp(startY), XScr2Bmp(X), YScr2Bmp(Y));
     end
     else
     begin
       if DrawBorderOpague1.Checked then
         Transparency := 255
       else
         Transparency := ((StrToInt(Opacity1.Text) * 255) div 100);
       IEBitmap.Canvas.Ellipse(XScr2Bmp(startX), YScr2Bmp(startY), XScr2Bmp(X), YScr2Bmp(Y));
       IEBitmap.Canvas.Pen.Color := PaintColor.Color;
       IEBitmap.Canvas.Brush.Color := FillColor.Color;
       IEBitmap.AlphaChannel.Canvas.Brush.Color := FillColor.Color;
       IEBitmap.Canvas.Brush.Style := bsSolid;
       IEBitmap.AlphaChannel.Canvas.Pen.Color := $02000000 or (Transparency) or (Transparency shl 8) or (Transparency shl 16);
       Transparency := ((StrToInt(Opacity1.Text) * 255) div 100);
       IEBitmap.AlphaChannel.Canvas.Brush.Color := $02000000 or (Transparency) or (Transparency shl 8) or (Transparency shl 16);
       if DrawBorderOpague1.Checked then
         Transparency := 255
       else
         Transparency := ((StrToInt(Opacity1.Text) * 255) div 100);
       IEBitmap.AlphaChannel.Canvas.Ellipse(XScr2Bmp(startX), YScr2Bmp(startY), XScr2Bmp(X), YScr2Bmp(Y));
     end;
  Update;
end;


You will get much nicer drawings if you use a TIECanvas that uses GDIPlus:
procedure TForm1.DrawFilledEllipse;
{Draw a filled ellipse}
var
  iPenSize: integer;
  iPenColor: TColor;
  iPenAlpha: integer;
  iBrushColor: TColor;
  iBrushAlpha: integer;
begin
  MyUndo(ImageEnView1);
  // Draw on the Non-Alpha Canvas
  NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
  iPenSize := StrToInt(BrushSize1.Text);
  iPenColor := PenColor1.Selected;
  iPenAlpha := StrToInt(PenAlpha1.Text);
  iBrushColor := BrushColor1.Selected;
  iBrushAlpha := StrToInt(BrushAlpha1.Text);
  NewCanvas.Pen.Color := iPenColor;
  NewCanvas.Pen.Style := psSolid;
  NewCanvas.Pen.Width := iPenSize;
  NewCanvas.Brush.Color := iBrushColor;
  NewCanvas.Brush.BackColor := iBrushColor;
  NewCanvas.Brush.Style := bsSolid;
  NewCanvas.Brush.Transparency := iBrushAlpha;
  NewCanvas.Brush.BackTransparency := iBrushAlpha;
  NewCanvas.Ellipse(startX, startY, PX + iPenSize, PY + iPenSize);
  NewCanvas.Free();
  ImageEnView1.IEBitmap.AlphaChannel.CanvasCurrentAlpha := iPenAlpha;
  // Draw on the Alpha Canvas
  // Note: do not assign color here... it will overwrite the alphachannel
  // Note: unless you assign the AlphaChannel.CanvasCurrentAlpha the pen has an alpha of 0 even though
  // NewCanvas.Pen.Transparency is set before drawing
  NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.AlphaChannel.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
  NewCanvas.Pen.Width := iPenSize;
  NewCanvas.Pen.Style := psSolid;
  NewCanvas.Brush.Style := bsSolid;
  NewCanvas.Brush.Transparency := iBrushAlpha;
  NewCanvas.Brush.BackTransparency := iBrushAlpha;
  NewCanvas.Ellipse(startX, startY, PX + iPenSize, PY + iPenSize);
  NewCanvas.Free();
  ImageEnView1.IEBitmap.AlphaChannel.CanvasCurrentAlpha := iBrushAlpha;
  ImageEnView1.Bitmap.Modified := True;
end;


My EBook has a GDIPlus- TIECanvas demonstration project in a zip file that is included with the EBook as well as some paragraphs about using TIECanvas.


645.11 KB

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

GregoryW

8 Posts

Posted - Nov 21 2012 :  21:34:56  Show Profile  Reply
Thank you! I'll try using your code in my application.

Greg
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: