Recent

Author Topic: TBRGABitmap Resample(...)  (Read 3127 times)

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
TBRGABitmap Resample(...)
« on: July 01, 2018, 09:30:56 am »
Hi I have been going around in circles trying to Resample a TBGRABitmap

I am sure that I am missing something very obvious...

 
Code: Pascal  [Select][+][-]
  1.  
  2.   // Always works as a test...
  3.    //    Image_Btabb_thumbnail.Picture.bitmap.Assign(global_main_image.Bitmap);
  4.  
  5.      // Both top two creation methods are definitely loading a displayable image...
  6.  
  7.    // thumbNail:= tbgrabitmap.Create(global_main_image.Bitmap);
  8.     thumbNail:= tbgrabitmap.Create(global_FileName_plain);
  9.    //   thumbNail:= tbgrabitmap.Create;
  10.  
  11.      try
  12.  
  13.   // This works...
  14.   // Image_Btabb_thumbnail.Picture.bitmap.Assign(thumbNail.Bitmap);
  15.  
  16.  //   showmessage('ok');
  17.  
  18.   thumbNail.ResampleFilter:= rfBestQuality;
  19.  
  20.    // This comes out blank
  21.         BGRAReplace(thumbNail,
  22.                        thumbNail.Resample(
  23.                         newWidth, newHeight,
  24.                          rmFineResample)
  25.                      );
  26.  
  27.            // This does not imrpove anything
  28.            // thumbNail.InvalidateBitmap;
  29.  
  30.  
  31.  //     showmessage('ok');
  32.  
  33.  {
  34.      // this never works ...
  35.  
  36.      global_main_image.ResampleFilter:= rfBestQuality;
  37.  
  38.    thumbNail :=  global_main_image.Resample(
  39.                         newWidth, newHeight,
  40.                          rmFineResample)
  41.                  as TBGRABitmap;
  42.    }
  43.  
  44.  
  45.         Application.ProcessMessages;
  46.          //
  47.  
  48.  //   // this always  comes out blank after re-sample...
  49.  
  50.      Image_Btabb_thumbnail.Picture.bitmap.Assign(thumbNail.Bitmap);
  51.  
  52.    // And so, of course this only produces "data:image" and nothing else...
  53.  
  54.           thumbString :=  thumbNail.Canvas2D.toDataURL('image/jpeg');  
  55.  
  56.  

Any help appreciates please,

Paul

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: TBRGABitmap Resample(...)
« Reply #1 on: July 01, 2018, 04:30:16 pm »
If I remember correctly is like this:
Code: Pascal  [Select][+][-]
  1. BGRAReplace(Bitmap, Bitmap.Resample(...) as TBGRABitmap)

PaulANormanNZ

  • Full Member
  • ***
  • Posts: 117
Re: TBRGABitmap Resample(...)
« Reply #2 on: July 02, 2018, 02:20:31 am »
Thanks Lainz,

I was looking at ...

http://wiki.freepascal.org/BGRABitmap_tutorial_5

Which shows it in this form...

Code: Pascal  [Select][+][-]
  1.  //load and scale texture
  2.   tex := TBGRABitmap.Create('texture.png');
  3.   BGRAReplace(tex,tex.Resample(128,80));
  4.  

which doesn't show the cast..

Code: Pascal  [Select][+][-]
  1. BGRAReplace(Bitmap, Bitmap.Resample(...) as TBGRABitmap)

I really appreciate the tutorials, they cover some amazing capabilities - is there though some straight forward primers anywhere which go over many of the more mundane use case scenarios, like these sorts of things, just processing images for web, storage in base64 etc...

Often people say look at the LazPaint code, but it is not a straight forward "design time" interface the way it is done.

Thanks,
paul


lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: TBRGABitmap Resample(...)
« Reply #3 on: July 02, 2018, 02:26:24 am »
Yes, I was writting it from my memories only =)

You can attach a small program that reproduces the problem? Usually when you do that, you can find the problem, and if not, we can try to help.

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: TBRGABitmap Resample(...)
« Reply #4 on: July 02, 2018, 02:52:10 am »
This works for me:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, BGRABitmap,
  9.   BGRABitmapTypes;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Image1: TImage;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormDestroy(Sender: TObject);
  19.   private
  20.     bitmap: TBGRABitmap;
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. begin
  36.   bitmap := TBGRABitmap.Create('image.png');
  37.   bitmap.ResampleFilter := rfBestQuality;
  38.   BGRAReplace(bitmap, bitmap.Resample(Image1.Width, Image1.Height));
  39.   Image1.Picture.Bitmap.Assign(bitmap.Bitmap);
  40.  
  41.   ShowMessage(bitmap.Canvas2D.toDataURL('image/jpeg'));
  42. end;
  43.  
  44. procedure TForm1.FormDestroy(Sender: TObject);
  45. begin
  46.   bitmap.Free;
  47. end;
  48.  
  49. end.
  50.        

 

TinyPortal © 2005-2018