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
 Ellipse Cutout Has Gray Background, How 2 Remove ?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

andyhill

Australia
133 Posts

Posted - Feb 26 2021 :  03:27:25  Show Profile  Reply
With or without the mask code I get an identical cutout that has soft gray corners outside of selection (I want white), can anyone help please ? Thanks

            ie.IEBitmap.Assign(IEBmp); // Source Image

            if EllipseFlag = True then begin
              // Init
              IEBmp2:= TIEBitmap.Create;
              IEBmp2.Width:= w;
              IEBmp2.Height:= h;
              IEBmp2.PixelFormat:= ie24RGB;
              IEBmp2.Fill(clWhite);
              // Calc Center
              w:= x2-x1;
              cx:= w div 2;
              h:= y2-y1;
              cy:= h div 2;
              // Cutout Ellipse
              ie.SelectionMask.SetEllipse(cx, cy, w, h, 1);
              ie.CopySelectionToIEBitmap(IEBmp2);
              ie.ClearAll();
              ie.IEBitmap.Assign(IEBmp2); // Layer 0

              //////////////////////////////////////////////////////////////////
              // Mask Attempt
              ie.LayersAdd(ielkImage);    // Layer 1
              ie.IEBitmap.Assign(IEBmp2);
              TIEImageLayer(ie.CurrentLayer).IsMask:= True;
              ie.CurrentLayer.FillColor2:= clBlack; // 100% masking
              ie.CurrentLayer.FillColor:= clWhite;  // 0% masking
              ie.CurrentLayer.MaskInverted:= False;
              ie.CurrentLayer.Visible:= False;
              ie.CurrentLayer.PosX:= 0;
              ie.CurrentLayer.PosY:= 0;
              ie.CurrentLayer.Width:= ie.Layers[0].Width;
              ie.CurrentLayer.Height:= ie.Layers[0].Height;
              //////////////////////////////////////////////////////////////////

              IEBmp2.Free;
            end;



Andy

xequte

38191 Posts

Posted - Feb 28 2021 :  17:18:39  Show Profile  Reply
Hi Andy

I personally find it easier to work with the alpha channel.

Here is an example of creating an image with a solid elliptical area and drawing that onto a white image.

var
  bmp : TIEBitmap;
  w, h: Integer;
begin
  // Create a TIEBitmap with a solid elliptical image in centre
  bmp := TIEBitmap.Create;
  Try
    bmp.read('D:\im.jpg');

    // Calc Center
    w  := bmp.Width;
    h  := bmp.Height;

    // Make canvas fully transparent
    bmp.AlphaFill(0);

    // Draw ellipse on alpha channel
    with bmp.AlphaChannel.IECanvas do
    begin
      Pen.Style := psSolid;
      Pen.Mode  := pmCopy;
      Pen.Color := clRed;
      Brush.Style := bsSolid;
      Ellipse( 0, 0, w, h );
    end;

    // Uncomment to see this image
    // bmp.Write('D:\transparent.png');

    // Create all white image in TImageEnView
    ImageEnView1.IEBitmap.Allocate( w, h, clWhite, 255 );

    // Draw our bitmap onto it
    bmp.DrawToTIEBitmap( ImageEnView1.IEBitmap, 0, 0 );

    // Refresh view
    ImageEnView1.Update();

  Finally
    bmp.Free;
  End;






Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: