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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Transparent Canvas?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
GregoryW Posted - Nov 20 2012 : 23:06:28
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
2   L A T E S T    R E P L I E S    (Newest First)
GregoryW Posted - Nov 21 2012 : 21:34:56
Thank you! I'll try using your code in my application.

Greg
w2m Posted - Nov 21 2012 : 09:37:19
// 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