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
 Draw on TIECanvas alphachannel
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Jun 24 2012 :  16:40:15  Show Profile  Reply
The code below works but it is not what I wanted to do. The commented IECanvas code does not work at all... meaning nothing is painted on the alphachannel. The uncommented code draws to the alphachannel ok, but how do you do it with IECanvas?

What dumb thing am I doing wrong?

procedure TForm1.DrawFilledRectangle;
var
  iTransparency: integer;
begin
  MyUndo(ImageEnView1);
  // Set the current alpha
  ImageEnView1.IEBitmap.AlphaChannel.CanvasCurrentAlpha := StrToInt(BrushAlpha1.Text);
  // Draw on the IEBitmap canvas
  NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
  NewCanvas.Pen.Width := StrToIntDef(BrushSize1.Text, 20);
  NewCanvas.Pen.Transparency := StrToInt(PenAlpha1.Text);
  NewCanvas.Pen.Color := PenColor1.Selected;
  NewCanvas.Brush.Transparency := StrToInt(BrushAlpha1.Text);
  NewCanvas.Brush.BackTransparency := StrToInt(BrushAlpha1.Text);
  NewCanvas.Brush.Color := BrushColor1.Selected;
  NewCanvas.Brush.Style := bsSolid;
  NewCanvas.SmoothingMode := TIECanvasSmoothingMode(IECanvasSmoothingMode1.ItemIndex);
  NewCanvas.Rectangle(StartX, StartY, PX + StrToInt(BrushSize1.Text), PY + StrToInt(BrushSize1.Text));
  NewCanvas.Free;

  // Draw on the alphachannel
 // This is commented because it does not work at all
  { MyUndo(ImageEnView1);
   //ImageEnView1.Layers[ImageEnView1.LayersCurrent].Bitmap.AlphaChannel.CanvasCurrentAlpha := StrToInt(BrushAlpha1.Text);
   NewCanvas := TIECanvas.Create(ImageEnView1.IEBitmap.AlphaChannel.Canvas, AntiAlias1.Checked, UseGDIPlus1.Checked);
   NewCanvas.Pen.Width := StrToIntDef(BrushSize1.Text, 20);
   NewCanvas.Pen.Transparency := StrToInt(PenAlpha1.Text);
   NewCanvas.Pen.Color := PenColor1.Selected;
   NewCanvas.Brush.Transparency := StrToInt(BrushAlpha1.Text);
   NewCanvas.Brush.BackTransparency := StrToInt(BrushAlpha1.Text);
   NewCanvas.Brush.Color := BrushColor1.Selected;
   NewCanvas.Brush.Style := bsClear;
   NewCanvas.SmoothingMode := TIECanvasSmoothingMode(IECanvasSmoothingMode1.ItemIndex);
   NewCanvas.Rectangle(StartX, StartY, PX + StrToInt(BrushSize1.Text), PY + StrToInt(BrushSize1.Text));
   NewCanvas.Free; }

// this works but it is not using a TIECanvas
  iTransparency := StrToInt(PenAlpha1.Text);
  ImageEnView1.IEBitmap.AlphaChannel.Canvas.Pen.Color := $02000000 or (iTransparency) or (iTransparency shl 8)
    or (iTransparency shl 16);
  ImageEnView1.IEBitmap.AlphaChannel.Canvas.Pen.Width := StrToIntDef(BrushSize1.Text, 20);
  ImageENView1.IEBitmap.AlphaChannel.Canvas.Brush.Color := $02000000 or (iTransparency) or
    (iTransparency shl 8) or (iTransparency shl 16);
  ImageEnView1.IEBitmap.AlphaChannel.Canvas.Brush.Style := bsSolid;
  ImageEnView1.IEBitmap.AlphaChannel.Canvas.Rectangle(startX, startY, PX + StrToInt(BrushSize1.Text), PY +
    StrToInt(BrushSize1.Text));
  ImageEnView1.Update;
  ImageEnView1.Bitmap.Modified := True;
end;


William Miller

w2m

USA
1990 Posts

Posted - Jun 26 2012 :  16:11:02  Show Profile  Reply
No answers, but I managed to get it to work. I think the problem was caused by setting pen or brush colors in the ImageEnView1.IEBitmap.AlphaChannel.Canvas.

procedure TForm1.DrawFilledRectangle;
{Draw a filled rectangle}
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.Transparency := iPenAlpha;
  NewCanvas.Pen.Style := psSolid;
  NewCanvas.Pen.Width := iPenSize;
  NewCanvas.Brush.Color := iBrushColor;
  NewCanvas.Brush.Style := bsSolid;
  NewCanvas.Brush.Transparency := iBrushAlpha;
  NewCanvas.Brush.BackTransparency := iBrushAlpha;
  NewCanvas.Rectangle(startX, startY, PX + iPenSize, PY + iPenSize);
  NewCanvas.Free();
  // Draw on the Alpha Canvas
  // Note: do not assign color here... it will overwrite the alphachannel
  ImageEnView1.IEBitmap.AlphaChannel.CanvasCurrentAlpha := iPenAlpha;
  // Note: unless you assign the AlphaChannel.CanvasCurrentAlpha the pen is not visible 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.Pen.Transparency := iPenAlpha;
  NewCanvas.Brush.Style := bsSolid;
  NewCanvas.Brush.Transparency := iBrushAlpha;
  NewCanvas.Brush.BackTransparency := iBrushAlpha;
  NewCanvas.Rectangle(startX, startY, PX + iPenSize, PY + iPenSize);
  NewCanvas.Free();
  ImageEnView1.Update;
  ImageEnView1.Bitmap.Modified := True;
end;


The strange thing I find now is that after the rectangle is drawn, I get the alpha under the mouse cursor in OnMouseMove, but the value returned is close to what it was set at when drawing not not exactly.
For example if the alpha is 255 when drawing, iAlpha in ImageEnView1MouseMove returns 252 instead of 255. if the alpha is 102 when drawing, iAlpha in ImageEnView1MouseMove returns 100 instead of 102?
I have never seen this before with ImageEn unless running TIECanvas... is there a bug in ImageEn or am I still working with the alphachannel drawing incorrectly?


procedure TForm1.ImageEnView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  BX, BY: Integer;
  iAlpha: integer;
begin
  BX := ImageEnView1.XScr2Bmp(X);
  BY := ImageEnView1.YScr2Bmp(Y);
  iAlpha := ImageEnView1.IEBitmap.Alpha[BX, BY];
  AlphaUnderCursor1.Caption := 'Alpha: ' + IntToStr(iAlpha);
  OpacityUnderCursor1.Caption := 'Opacity: ' + IntToStr 
    (IEAlphaToOpacity(iAlpha)) + '%';
end;


William Miller
Go to Top of Page

fab

1310 Posts

Posted - Jun 26 2012 :  21:55:21  Show Profile  Reply
For example if the alpha is 255 when drawing, iAlpha in ImageEnView1MouseMove returns 252 instead of 255. if the alpha is 102 when drawing, iAlpha in ImageEnView1MouseMove returns 100 instead of 102?


It should be due the antialias option. Try to disable it in TIECanvas constructor.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: