Recent

Author Topic: [SOLVED] Resize Bitmap Has Me Stumped  (Read 1223 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] Resize Bitmap Has Me Stumped
« on: August 24, 2019, 03:32:07 pm »
Okay... follow along closely.
I am using a 2D to 3D Phong Filter on my image (Lainz provided the code that did the phong)

I have a "Design" window (using notebook) where the phong works fine.
When I click an "Export" button I assign the entire bitmap into a "new3D" Bitmap... that works fine.

After the "Export" window displays I have two choices of resizing. 1) Original Size and 2) Custom Size
The Original Size works fine... The "new3D" bitmap fills the BGRAGraphicControl perfectly.
FYI... the Export just brings me to an Export window.

However, when I click the "Custom Size", the control changes to the correct size, but the "new3D" image resizes, but it is way to small and doesn't fit the control.
I doubled checked my code to make sure I am getting the original size bitmap and I am.

So, I am not sure what is happening. Maybe another set of eyes can see something I am not.

Here is my Export button code that sets the Phong image from the Control on the Design window
And just so you know, the original is the size of the control you see in screenshot below.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.mnuExportImgClick(Sender: TObject);
  3. begin
  4.  nb.PageIndex:=2;
  5.  
  6.  BGRAGraphicControl2.DiscardBitmap;
  7.  
  8.  {reldaw current bitmap}
  9.   theBMP:= TBGRABitmap.Create(txtImpImg.Text);
  10.   BGRAGraphicControl2.Width:=theBMP.width;
  11.   BGRAGraphicControl2.Height:=theBMP.height;
  12.   Image2.Width:=theBMP.width;
  13.   Image2.Height:=theBMP.height;
  14.  
  15.  newBMP:= TBGRABitmap.Create(theBMP.Bitmap);
  16.  newBMP.PutImage(0, 0, theBMP, dmDrawWithTransparency );
  17.  
  18.  bmp := TBGRABitmap.Create(theBMP);
  19.  new3D:= TBGRABitmap.Create(BGRAGraphicControl1.Bitmap); //<-- THIS IS WHERE I FETCH THE BITMAP OFF THE DESIGN WINDOW
  20.                                                                       // THIS WORKS FINE
  21.  
  22.  

This is my code that draws the "new3D" bitmap
This works fine too

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.BGRAGraphicControl2Redraw(Sender: TObject; Bitmap: TBGRABitmap
  3.   );
  4. begin
  5.      BGRAGraphicControl2.Bitmap.Assign(new3D);
  6. end;
  7.  
  8.  

Here is the code that does the custom Resizing
This code doesn't work right

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.opt5Change(Sender: TObject);
  3. begin
  4.  
  5.    BGRAGraphicControl2.DiscardBitmap;
  6.  
  7.    //resize visual controls
  8.    Image2.Width:=StrToInt(Edit1.Text);
  9.    Image2.Height:=StrToInt(Edit2.Text);
  10.    BGRAGraphicControl2.width:=StrToInt(Edit1.Text);
  11.    BGRAGraphicControl2.Height:=StrToInt(Edit2.Text);
  12.  
  13.    //resize bitmap
  14.    newBMP:= TBGRABitmap.Create(BGRAGraphicControl1.Bitmap); //<-- I GET THE ORIGINAL BITMAP - THIS WORKS
  15.    newBMP.ResampleFilter:= rfBestQuality;
  16.    BGRAReplace(newBMP, newBMP.Resample(StrToInt(Edit1.Text), StrToInt(Edit2.Text)));
  17.  
  18.    new3D.Assign(newBMP);
  19.  
  20. end;    
  21.  
  22.  

Attached is a screenshot of the small bitmap that should be filling the control




« Last Edit: August 24, 2019, 09:03:23 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: Resize Bitmap Has Me Stumped
« Reply #1 on: August 24, 2019, 09:03:07 pm »
I figured it out.


I had assigned a transparent bitmap that I for got to remove when resizing.


The redraw was grabbing the transparent and "new3D" together... thus the really small drawing.




Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018