Code makes a bsod lazarus / 39-Graphics ---------------------------------------------------------------------- calebs · 2022-02-10 17:50 This piece of code caused a bsod and ruined my lazarus installation im on windows 11 pro x64, lazarus 2.2.0. I'm trying to print an image to a printer canvas image1 is a timage on form canvas is printer canvas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  bmp := TBitmap.Create;    if tipocomandera='0' then begin      image1.Width:=100;      image1.Height:=100;    end else begin      image1.Width:=200;      image1.Height:=200;    end;    anchot:=image1.Width;    altot:=image1.Height;    R := Rect(0, 0, anchot, altot);    r2:= rect(0,10,anchot,10+altot);    bmp.SetSize(anchot, altot);    bmp.Canvas.Brush.Color := clWhite;    bmp.Canvas.FillRect(R);    if not modof then begin//      image1.PaintOnCanvas(bmp.Canvas, R);      canvas.CopyRect(r2,image1.Canvas,r);    end;                         i ve used this code with an a tbarcode image and worked well. I guess it will not work for timage after bsod have to remove lazarus installation and reinstall ---------------------------------------------------------------------- winni · 2022-02-10 18:26 Hi! If you change the size of an TImage you have also to change the size of the included TBitmap: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Image1.width := 200;Image1.height := 200;Image1.Picture.Bitmap.SetSize(Image1.width, Image1.height);  Winni ---------------------------------------------------------------------- wp · 2022-02-10 18:55 I don't understand this code: - you create a TBitmap - you set the size of Image1 - you set the size of the bitmap to be equal to that of the image. - you completely fill the bitmap with white color - you copy part of the image to some canvas What I don't understand is: - how is the bitmap related to the image? From your code is do not see why the bitmap is needed at all. - To which object does the canvas belong to which you copy the image? Does it exist at all? Is it the canvas of the bitmap? In this case you must call bmp.Canvas.CopyRect(...). Or the canvas of the printer? In this case you must call: Printer.canvas.CopyRect? But is the printer ready for printing? Please do not show such fragments of code which reveal a great part of what you are doing. Always ask yourself: Would I understand this problem if somebody else would give me exactly this information? ---------------------------------------------------------------------- calebs · 2022-02-18 15:55 Sorry. This is the same code i used to print a qbarcode image with modifications. this code is working fine with barcode component where barcodeqr1 : TBarcodeQR cad : string bmp: TBitmap rectt, R, r2: TRect modof: boolean all wrapped in a with printer do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       BarcodeQR1.Text:=cad;      bmp := TBitmap.Create;      R := Rect(0, 0, BarcodeQR1.Width, BarcodeQR1.Height);      r2:= rect(0,ypos+10,BarcodeQR1.Width,ypos+10+BarcodeQR1.Height);      bmp.SetSize(BarcodeQR1.Width, BarcodeQR1.Height);      bmp.Canvas.Brush.Color := clWhite;      bmp.Canvas.FillRect(R);      if not modof then begin        BarcodeQR1.PaintOnCanvas(bmp.Canvas, R);        canvas.CopyRect(r2,bmp.canvas,r);      end;  this code worked as expected i try to reuse this code but with an timage with my lack of understanding of what i was doing and it causes a bsod. anyway, searching in the forums find a way to achieve what i want to do.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           logoancho:=100;          logoalto:=100;        logomargensup:=10;      logomargender:=20;        image1.Width:=logoancho;        image1.Height:=logoalto;        printer.canvas.StretchDraw(rect(anchopagina-logoancho- logomargender,logomargensup,anchopagina- logomargender,logomargensup+logoalto),Image1.Picture.Bitmap);       with that code i cant put an image on the printer canvas. ive posted the code that causes a bsod as a curiosity not knowing why happened. Thanks! ---------------------------------------------------------------------- Thaddy · 2022-02-18 16:05 Did you think about checking your hardware first? Computers tend to die. (or go in coma) Otherwise use the crt unit to simulate a proper bsod. ( But that is for 1 of April) ---------------------------------------------------------------------- winni · 2022-02-18 18:16 Hi! I told you above: If you change the size of a Timage you also have to change the size of the Timage.picture.bitmap !!! Why don't you do that??? Winni ---------------------------------------------------------------------- wp · 2022-02-18 18:39 Quote from: winni on February 18, 2022, 07:16:17 pmIf you change the size of a Timage you also have to change the size of the Timage.picture.bitmap !!! No. Put a client-aligned TImage on a form, load some picture. Compile and run. Resize the form which resizes the image. There is no crash although the bitmap is unchanged. When the loaded picture  is larger than the TImage then you only see a smaller or larger section of the image. ---------------------------------------------------------------------- winni · 2022-02-18 18:50 @wp: You are right with an existing and designed TImage. But his Timage is dynamicaly created at runtime. In this case if you don't change the size of the bitmap the app might crash. Painful experience. Winni ---------------------------------------------------------------------- wp · 2022-02-18 20:55 Your crystal ball must be clearer than mine so that you understand what the OP is doing in his code fragments. Still cannot reproduce this issue from your description, winni. The following code does not crash when the image is resized. The image is now created dynamically at runtime, and the bitmap still is not changed after loading. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  FImage := TImage.Create(self);  FImage.Align := alClient;  FImage.Parent := self;  FImage.Picture.LoadFromFile('C:\Lazarus\lazarus- main_fpc-3.2.2\images\splash_source\cheetah.jpg');end; ---------------------------------------------------------------------- winni · 2022-02-18 21:47 Hi! Look at calebs code. That is not the way he does code. Winni ---------------------------------------------------------------------- wp · 2022-02-18 21:55 As I wrote above, I don't understand his code. Besides the same size, there is no connection between the image and the bmp. ---------------------------------------------------------------------- rvk · 2022-02-18 23:21 Quote from: winni on February 18, 2022, 07:50:00 pmBut his Timage is dynamicaly created at runtime. Quote from: calebs on February 10, 2022, 06:50:07 pmimage1 is a timage on form Maybe some reproducible code would be nice. I'd like to have some code in pure pascal that can cause a bsod