Recent

Author Topic: Pasting to BGRA Bitmap - [Solved]  (Read 1112 times)

zxandris

  • Full Member
  • ***
  • Posts: 170
Pasting to BGRA Bitmap - [Solved]
« on: December 21, 2024, 04:23:23 pm »
Okay I've had a look around and the code below doesn't appear to work, and I can't see why.  I saved from the picture object to check and it's just empty.  Any help would be appreciated.

Code: Pascal  [Select][+][-]
  1. procedure TframeImageViewer.actIVPasteExecute(Sender: TObject);
  2. var
  3.    pic : TPicture;
  4. begin
  5.     // WIP
  6.     Pic := TPicture.Create;
  7.     try
  8.        if clipboard.HasFormat(CF_Picture) then
  9.        begin
  10.             if not assigned(BgraView) then BgraView := TBgraBitmap.create(0,0, BGRAPixelTransparent);
  11.             try
  12.                 pic.Bitmap.LoadFromClipboardFormat(CF_Picture);
  13.                 BgraView.SetSize(pic.Bitmap.width, pic.bitmap.height);
  14.                 BgraView.Canvas.Draw(0, 0, pic.graphic);
  15.                 rst.x := bgraView.width;
  16.                 rst.y := bgraView.Height;
  17.                 pnlImage.Repaint;
  18.             except
  19.                   //
  20.             end;
  21.        end;
  22.     finally
  23.            pic.free;
  24.     end;
  25. end;
  26.  
« Last Edit: December 21, 2024, 04:44:57 pm by zxandris »

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Pasting to BGRA Bitmap
« Reply #1 on: December 21, 2024, 04:26:24 pm »
Okay did more searching and fiddling and this works...
Code: Pascal  [Select][+][-]
  1. procedure TframeImageViewer.actIVPasteExecute(Sender: TObject);
  2. var
  3.    pic : TPicture;
  4.    bmp : TBitmap;
  5. begin
  6.     // WIP
  7.     if Clipboard.HasPictureFormat then begin
  8.        bmp := tbitmap.Create;
  9.        try
  10.           bmp.Assign(Clipboard);
  11.           if not assigned(BgraView) then BgraView := TBgraBitmap.create(0,0, BGRAPixelTransparent);
  12.           try
  13.               BgraView.SetSize(bmp.width, bmp.height);
  14.               BgraView.Canvas.Draw(0, 0, bmp);
  15.               rst.x := bgraView.width;
  16.               rst.y := bgraView.Height;
  17.               pnlImage.Repaint;
  18.           except
  19.                 //
  20.           end;
  21.        finally
  22.               bmp.free;
  23.        end;
  24.     end;
  25.  

But how to I paste and maintain the alpha, would anyone know that?

zxandris

  • Full Member
  • ***
  • Posts: 170
Re: Pasting to BGRA Bitmap
« Reply #2 on: December 21, 2024, 04:44:40 pm »
Okay on further searching and a little testing, these seem to maintain transparency between applications.

Copy
Code: Pascal  [Select][+][-]
  1. var
  2.    bmp : TBitmap;
  3. begin
  4.      // This seems to copy transparency
  5.      if assigned(BgraView) then
  6.      begin
  7.         bmp := TBitmap.create;
  8.         try
  9.             bmp := BgraView.MakeBitmapCopy(clNone, false);
  10.             Clipboard.Open;
  11.             CLipboard.Assign(bmp);
  12.             clipboard.Close;
  13.         finally
  14.                bmp.free;
  15.         end;
  16.     end;
  17. end;
  18.  

Paste
Code: Pascal  [Select][+][-]
  1. procedure TframeImageViewer.actIVPasteExecute(Sender: TObject);
  2. var
  3.    bmp : TBitmap;
  4. begin
  5.     // WIP
  6.     if Clipboard.HasPictureFormat then
  7.     begin
  8.            bmp := tbitmap.Create;
  9.            try
  10.               bmp.Assign(Clipboard);
  11.               if not assigned(BgraView) then BgraView := TBgraBitmap.create(0,0, BGRAPixelTransparent);
  12.               try
  13.                   BgraView.SetSize(bmp.width, bmp.height);
  14.                   BgraView.Canvas.Draw(0, 0, bmp);
  15.                   rst.x := bgraView.width;
  16.                   rst.y := bgraView.Height;
  17.                   pnlImage.Repaint;
  18.               except
  19.                     //
  20.               end;
  21.            finally
  22.                   bmp.free;
  23.            end;
  24.     end;
  25. end;
  26.  

Now obviously those are from my app, but could easily be changed. I thought I would offer them here for those also looking for a solution to this.

 

TinyPortal © 2005-2018