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
 Erasing on a transparent layer
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

ElCef

4 Posts

Posted - Sep 05 2013 :  04:00:56  Show Profile  Reply
Hi, i'm trying to build a sort of blackboard application:
I load a background image in the first layer of an Imageenview comp, then I create a second layer over the first, make it transparent via SetTransparentColors, then handle OnMouseDown/OnMouseMove to paint over it.
Painting this way works correctly, but how can I code an eraser tool?

w2m

USA
1990 Posts

Posted - Sep 05 2013 :  07:00:52  Show Profile  Reply
When painting, set the pixel color and alpha value on the layer which I assume you are doing now. To erase the drawn pixels, set the alpha value of the pixels to 0. This is essentially the same as your color painting code, except you paint the alpha value but not the color. This will allow the pixels in layer 0 to be visible.

The code for erasing a pixel in the OnMouseDown event is shown below. This code will not erase unless there is a transparent layer over the background image in layer 0.
procedure TForm1.ImageEnViewMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
{ Respond to a mouse down. }
var
  iP1: TPoint;
  iTransparency: Integer;
  iRGB: TRGB;
  iColor: TColor;
begin
  mx := X;
  my := Y;
  lx := X;
  ly := Y;
  APX := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvXScr2Bmp(X);
  APY := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvYScr2Bmp(Y);
  AStartX := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvXScr2Bmp(X);
  AstartY := ImageEnView.Layers[ImageEnView.LayersCurrent].ConvYScr2Bmp(Y);
  if (Button = mbRight) and (ImageEnView.MouseInteract <> [miZoom]) then
  dxBarPopupMenuImageEnView1.PopupFromCursorPos;
  if (Paint1.Down) and (ImageEnView.MouseCapture) then
  begin
    { Paint Point Color and Opacity }
    with ImageEnView do
    begin
      Proc.SaveUndoCaptioned('Paint Color And Alpha ' +
        IntToStr(Proc.UndoCount + 1));
      iP1.X := Layers[LayersCurrent].ConvXScr2Bmp(X);
      iP1.Y := Layers[LayersCurrent].ConvYScr2Bmp(Y);
      HighlightedPixel := iP1;
      iTransparency := PenAlpha1.EditValue;
      IEBitmap.Canvas.Pixels[Layers[LayersCurrent].ConvXScr2Bmp(X),
        ImageEnView.Layers[LayersCurrent].ConvYScr2Bmp(Y)] :=
          PenColor1.EditValue;
      IEBitmap.AlphaChannel.Canvas.Pen.Color := $02000000 or (iTransparency)
            or (iTransparency shl 8) or (iTransparency shl 16);
      IEBitmap.AlphaChannel.Canvas.Brush.Color := $02000000 or
         (iTransparency) or (iTransparency shl 8) or (iTransparency shl 16);
      IEBitmap.AlphaChannel.Canvas.Pixels
        [Layers[LayersCurrent].ConvXScr2Bmp(X),
           Layers[LayersCurrent].ConvYScr2Bmp(Y)] := PenColor1.EditValue;
      IEBitmap.Alpha[Layers[LayersCurrent].ConvXScr2Bmp(X),
        Layers[LayersCurrent].ConvYScr2Bmp(Y)] := iTransparency;
      Update;
      Bitmap.Modified := True;
    end;
  end
  else if (PaintColor1.Down) and (ImageEnView.MouseCapture) then
  begin
    { Paint Point Color }
    with ImageEnView do
    begin
      Proc.SaveUndoCaptioned('Paint Color ' + IntToStr(Proc.UndoCount + 1));
      iP1.X := Layers[LayersCurrent].ConvXScr2Bmp(X);
      iP1.Y := Layers[LayersCurrent].ConvYScr2Bmp(Y);
      HighlightedPixel := iP1;
      IEBitmap.Canvas.Pixels[Layers[LayersCurrent].ConvXScr2Bmp(X),
        ImageEnView.Layers[LayersCurrent].ConvYScr2Bmp(Y)] :=
        PenColor1.EditValue;
      Update;
      Bitmap.Modified := True;
    end;
  end
  else if (PaintAlpha1.Down) and (ImageEnView.MouseCapture) then
  begin
    { Paint Point Opacity }
    with ImageEnView do
    begin
      Proc.SaveUndoCaptioned('Paint Alpha ' + IntToStr(Proc.UndoCount + 1));
      iP1.X := Layers[LayersCurrent].ConvXScr2Bmp(X);
      iP1.Y := Layers[LayersCurrent].ConvYScr2Bmp(Y);
      HighlightedPixel := iP1;
      iTransparency := (IEOpacityToAlpha(PenOpacity1.EditValue));
      IEBitmap.AlphaChannel.Canvas.Pen.Color := $02000000 or (iTransparency)
        or (iTransparency shl 8) or (iTransparency shl 16);
          IEBitmap.AlphaChannel.Canvas.Brush.Color := $02000000 or
            (iTransparency) or (iTransparency shl 8) or (iTransparency shl 16);
      IEBitmap.AlphaChannel.Canvas.Pixels
        [Layers[LayersCurrent].ConvXScr2Bmp(X),
        Layers[LayersCurrent].ConvYScr2Bmp(Y)] := PenColor1.EditValue;
      IEBitmap.Alpha[Layers[LayersCurrent].ConvXScr2Bmp(X),
        Layers[LayersCurrent].ConvYScr2Bmp(Y)] := iTransparency;
      Update;
      Bitmap.Modified := True;
    end;
  end
  else if (Erase1.Down) and (ImageEnView.MouseCapture) then
  begin
    { Paint Point Opacity as 0}
    with ImageEnView do
     begin
       Proc.SaveUndoCaptioned('Erase ' + IntToStr(Proc.UndoCount + 1));
       iP1.X := Layers[LayersCurrent].ConvXScr2Bmp(X);
       iP1.Y := Layers[LayersCurrent].ConvYScr2Bmp(Y);
       HighlightedPixel := iP1;
       iTransparency := 0;
       IEBitmap.AlphaChannel.Canvas.Pen.Color := $02000000 or (iTransparency)
         or (iTransparency shl 8) or (iTransparency shl 16);
       IEBitmap.AlphaChannel.Canvas.Brush.Color := $02000000 or
         (iTransparency) or (iTransparency shl 8) or (iTransparency shl 16);
       IEBitmap.AlphaChannel.Canvas.Pixels
         [Layers[LayersCurrent].ConvXScr2Bmp(X),
         Layers[LayersCurrent].ConvYScr2Bmp(Y)] := PenColor1.EditValue;
       IEBitmap.Alpha[Layers[LayersCurrent].ConvXScr2Bmp(X),
         Layers[LayersCurrent].ConvYScr2Bmp(Y)] := iTransparency;
       Update;
       Bitmap.Modified := True;
     end;
   end;
...
The same code should also be placed in the OnMouseMove event. Similar code can be also used to draw with GDIPlus using an TIECanvas which allows using a brush to draw brush(size(> 1).

Also for those developing for touch screens. I just found out today that ImageEnView.MouseCapture handles touch so you do not have to handle the more complicated Shift parameter... ((Shift = [ssLeft]) or (Shift = [ssLeft, ssTouch]) or (Shift = [ssTouch])).

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

nwscomps

185 Posts

Posted - Sep 27 2013 :  09:24:33  Show Profile  Reply
Hello,
you can try our ImageEn Paint engine from our website: www.nwscomps.com
it has an erase layer tool and much more


Francesco Savastano
Nwscomps.com
Add-ons for the ImageEn Library
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: