FranzB 0 Posted August 27, 2020 (edited) I want to insert a bitmap on it's own left side again using canvas.drawbitmap function but actually this code does not do anything..... can't see my mistake here 😞 procedure InsertonMyleft(aBMP : TBitmap); var tempBMP: TBitmap; RecFull: TRectF; RecLeft: TRectF; begin tempBMP := TBitmap.Create; try aBMP.Canvas.BeginScene; tempBMP.Assign(localBMP); tempBMP.SaveToFile('c:\temp\debugme.bmp'); RecFull := RectF(0, 0, aBMP.Width, aBMP.Height); RecLeft := RectF(0, 0, round(aBMP.Width / 3), round(aBMP.Height / 1)); aBMP.Canvas.DrawBitmap(tempBMP, RecFull, RecLeft, 50, True); aBMP.Canvas.EndScene; aBMP.SaveToFile('c:\temp\debugme2.bmp'); finally tempBMP.Free; end; end; Edited August 27, 2020 by FranzB Share this post Link to post
Remy Lebeau 1397 Posted August 28, 2020 (edited) Where is localBMP coming from? You don't really need to make a copy of a TBitmap just to draw it, so you could just use localBMP as-is and get rid of tempBMP. Unless localBMP is actually supposed to be aBMP instead (typo?), then using tempBMP makes more sense if you are trying to draw a TBitmap onto itself. When calling DrawBitmap(), RecFull is supposed to be a rectangle within the TBItmap that you are drawing from, but you are setting it to the rectangle of the TBitmap that you are drawing onto. Change aBMP to tempBMP when populating RecFull. Edited August 28, 2020 by Remy Lebeau Share this post Link to post
FranzB 0 Posted August 29, 2020 I changed the code to make it a full separate process function like below , Trect full has correct size 0,0,500,500 and Trect left size is 0,0,250,500 image size is 501 x501 pixel but still no effect from this code 😞 procedure InsertonMyleft(aBMP : TBitmap); var tempBMP: TBitmap; RecFull: TRectF; RecLeft: TRectF; begin tempBMP := TBitmap.Create; try aBMP.Canvas.BeginScene; tempBMP.Assign(aBMP); tempBMP.SaveToFile('c:\temp\debugme.bmp'); RecFull := RectF(0, 0, aBMP.Width-1, aBMP.Height-1); // size of full trect, 0,0,500,500 RecLeft := RectF(0, 0, round((aBMP.Width-1) / 2), // just lest side round((aBMP.Height-1) / 1)); aBMP.Canvas.DrawBitmap(tempBMP, RecFull, RecLeft, 50, True); aBMP.Canvas.EndScene; aBMP.SaveToFile('c:\temp\debugme2.bmp'); finally tempBMP.Free; end; end; Share this post Link to post
Rollo62 536 Posted August 29, 2020 I think 0 ... 500 is not correct. Your ABmp seems to have 501 pixel with in the first place. Maybe forgot to set with-1 and height-1 in tue caller of the function ? Share this post Link to post
FranzB 0 Posted August 29, 2020 already changed to width-1 ...... see code above RecFull := RectF(0, 0, aBMP.Width-1, aBMP.Height-1); // size of full trect, 0,0,500,500 Share this post Link to post
Gustav Schubert 25 Posted August 29, 2020 (edited) Assign to tempBMP outside of BeginScene / EndScene? procedure TForm1.InsertOnMyLeft(aBMP: TBitmap); var tempBMP: TBitmap; RecFull: TRectF; RecLeft: TRectF; begin tempBMP := TBitmap.Create; try tempBMP.Assign(aBMP); // <-- aBMP.Canvas.BeginScene; RecFull := RectF(0, 0, aBMP.Width-1, aBMP.Height-1); RecLeft := RectF(0, 0, Round((aBMP.Width-1) / 2), Round((aBMP.Height-1) / 1)); aBMP.Canvas.DrawBitmap(tempBMP, RecFull, RecLeft, 0.5, True); aBMP.Canvas.EndScene; finally tempBMP.Free; end; end; Edited August 29, 2020 by Gustav Schubert Share this post Link to post
FranzB 0 Posted August 29, 2020 procedure InsertonMyleft(aBMP: TBitmap); var tempBMP: TBitmap; RecFull: TRectF; RecLeft: TRectF; begin tempBMP := TBitmap.Create; try // tempBMP.Assign(aBMP); // tempBMP.SaveToFile('c:\temp\debugme.bmp'); tempBMP.LOadfromFile('c:\temp\debugme3.bmp'); RecFull := RectF(0, 0, aBMP.Width - 2, aBMP.Height - 2); RecLeft := RectF(0, 0, round(aBMP.Width / 3), round((aBMP.Height - 1) / 1)); aBMP.Canvas.BeginScene; aBMP.Canvas.DrawBitmap(tempBMP, RecFull, RecLeft, 50, True); aBMP.Canvas.EndScene; aBMP.SaveToFile('c:\temp\debugme2.bmp'); finally tempBMP.Free; end; end; if I load a bitmap from a file , my code works fine but the assign sequence does not have the desired function, (insert the bmp on the left side) even the savetofile saved the correct bitmap content Share this post Link to post
Gustav Schubert 25 Posted August 30, 2020 9 hours ago, FranzB said: but the assign sequence does not have the desired function, (insert the bmp on the left side) The Opacity parameter should be between 0 and 1. RectF is not the problem, even if specified too large. A stretched version of the original (aBMP) is drawn on top of aBMP, as expected. I can see it in an Image component, and in the file on disk. TempBMP, a copy of aBMP is needed it seems, ok. I noticed that the copy of aBMP needs to be made outside of the BeginScene/EndScene block, ok? Can you reproduce a problem without saving to disk? What exactly is the problem - how do you show the image? { rectangle setup } SrcFull := RectF(0, 0, tempBMP.Width, tempBMP.Height); DstLeft := RectF(0, 0, aBMP.Width / 3, aBMP.Height); aBMP.Canvas.DrawBitmap(tempBMP, SrcFull, DstLeft, 1.0, True); Share this post Link to post