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
 paste a bmp into an object and adjust its opacity
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

zhengyuanyi27

58 Posts

Posted - Sep 15 2020 :  04:12:48  Show Profile  Reply
Dear all,
Is it possible to paste a bitmap into a selection ROI and adjust its opacity? I think it should use layer, but I don't know how to realize it. Thanks a lot!
Such as:
imageenvect1.Proc.CopyToClipboard(iecpauto) ;
ImageEnVect3.Proc.PasteFromClipboard(iecpSelection);
ImageEnVect3.Layers[layerscurrent].Opacity := 10;
imageenvect3.Update;


xequte

38180 Posts

Posted - Sep 15 2020 :  22:52:18  Show Profile  Reply
Hi

Please use LayersCreateFromClipboard:

ImageEnView1.Proc.CopyToClipboard(iecpAuto);
idx := ImageEnView2.Proc.LayersCreateFromClipboard();
ImageEnView2.Layers[idx].Opacity := 10;
ImageEnView2.Update();

https://www.imageen.com/help/TImageEnView.LayersCreateFromClipboard.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

zhengyuanyi27

58 Posts

Posted - Sep 24 2020 :  03:28:52  Show Profile  Reply
Thanks, Nigel!
I am Sorry. I made a mistake. I found what I really want is to paste the bmp with transparent background like ICO, NOT opacity.
I tried to set bitmap.transparentcolor:=clblack; (I want
to set the black color as transparent color. )
It doesn't work.
Could you please tell me how to make It work? Thanks a lot.
Go to Top of Page

xequte

38180 Posts

Posted - Sep 24 2020 :  05:55:45  Show Profile  Reply
Hi

So you are copying from an image that has alpha (background transparency) like ICO or PNG, and you want to paste it as a new layer (supporting the alpha).

Is that correct?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

zhengyuanyi27

58 Posts

Posted - Sep 24 2020 :  12:52:36  Show Profile  Reply
Dear Nigel,
Thanks.
I want to paste an bmp into the ROI selection region in an imageenvect, and the clblack pixels in the bmp should be transparent after being pasted into the roi region of imageenvect.

Thanks.

The following are the codes. It seems the pasted bmp is not transparent. The black pixels are still there.


procedure TplayAVI.ToolButton16Click(Sender: TObject);
var
    i,   j,   uG:   Integer;
    P:   PByteArray;
    bggray: integer;
    bmp:Tbitmap;
    layerno:integer;
begin
          ImageEnvect3.IEBitmap.Assign(imageenvect0.ieBitmap);
          imageenvect3.Update;

          IDSImageEnvect.Bitmap.Assign(imageenvect0.Bitmap);
          IDSimageenvect.Update;

          GrayToColor(IDSimageenvect.Bitmap);  //This procedure will turn the gray image into color image.
          IDSimageenvect.Proc.CopyToClipboard(iecpauto)  ;  //This will copy an ROI to the clipboard.

 //-------create bmp and get rid of the given pixels such as clblack pixels.
          bmp:=Tbitmap.Create;
          bmp.Assign(clipboard);
          bggray:= strtoint(backgroundgrayedit.Text) ;
          for   j   :=   0   to   Bmp.Height   -   1   do
          begin
                 P   :=   Bmp.ScanLine[j];
                for   i   :=   0   to   Bmp.Width   -   1   do
                begin
                      uG   :=   P[3   *   i];
                      if   ug< bggray then   //set the pixels to be clblack.
                      begin
                           P[3   *   i   +   2]   :=   0;
                           P[3   *   i   +   1]   :=   0;
                           P[3   *   i]   :=   0;
                     end;
                 end;
           end;
              Bmp.PixelFormat   :=   pf32bit;
              Bmp.TransparentColor:=clblack;   //set the black pixels in bmp to be transparent
              Bmp.Free;
  
              ImageEnVect3.Proc.PasteFromClipboard(iecpSelection);    //Paste the bmp file into the ROI in Imageenvect3.
              imageenvect3.Update;
end;
Go to Top of Page

xequte

38180 Posts

Posted - Sep 24 2020 :  18:46:58  Show Profile  Reply
OK, I don't see where you use BMP. But to use transparency in ImageEn you need to enable use the Alpha Channel of TIEBitmap (the alpha channel is basically a gray scale bitmap, where white is opaque, black is transparent and gray is semi-transparent)



https://www.imageen.com/help/TIEBitmap.AlphaChannel.html


If you are bringing in a pf32bit bitmap into ImageEn then you need to convert the bitmap A channel to ImageEn's Alpha Channel using SynchronizeRGBA

https://www.imageen.com/help/TIEBitmap.SynchronizeRGBA.html

e.g.

  ImageEnView1.IEBitmap.Assign( bmp );
  ImageEnView1.IEBitmap.SynchronizeRGBA( true );
  ImageEnView1.Update();



If you have a TIEBitmap and just want to set all the black pixels as transparent just use SetTransparentColors:

https://www.imageen.com/help/TIEBitmap.SetTransparentColors.html


e.g.

MyBMP.SetTransparentColors( clBlack, clBlack, 0 );



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

zhengyuanyi27

58 Posts

Posted - Sep 26 2020 :  03:15:51  Show Profile  Reply
Hi Nigel,
Thanks a lot.
It works!!!
I set the color transparent "imageenvect.Proc.SetTransparentColors( clBlack, clBlack, 0 );
And then copy it and paste it into the ROI.

All the best,
Yuanyi
Go to Top of Page

xequte

38180 Posts

Posted - Sep 27 2020 :  16:08:08  Show Profile  Reply
Excellent

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