Forum > Graphics

Lazarus GDI+ problem. Access Violation

(1/4) > >>

Nick00:
I am porting an application from Delphi to Lazarus. There was a problem with the following piece of code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses GDIPAPI, GDIPOBJ;...var ist:IStream;    ms:TMemoryStream;    img:TGPImage;begin    ...    //загрузка из БД blob поля в поток    (DS.FieldByName('IMAGE') as TBlobField).SaveToStream(ms);    //создание TGPImage    ms.Position:=0;    ist:=TStreamAdapter.Create(ms);    img:=TGPImage.Create(ist); // на этой строке возникает исключение    ...end;The problem is throwing an exception External: Access Violation... Write of address 00000000.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TGPImage constructor:constructor TGPImage.Create(stream: IStream;  useEmbeddedColorManagement: BOOL = FALSE);begin  nativeImage := nil;  if (useEmbeddedColorManagement) then    lastResult := GdipLoadImageFromStreamICM(stream, nativeImage)  else lastResult := GdipLoadImageFromStream(stream, nativeImage);end;The modules GDIPAPI, GDIPOBJ are identical for Delphi and Lazarus, except for the line

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IFDEF FPC} {$MODE Delphi} {$ENDIF}in modules for Lazarus.
For an ms stream, ms.Size in Delphi = ms.Size in Lazarus for a single database entry. Interestingly, if write

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ms.Position:=1;then an exception is not thrown, well, in img, of course, garbage.
Who has any ideas how to deal with the problem?

marcov:
If you save the memory stream to disc after the ms.position:=0, is the result a valid image or does it have some bytes prepended?

Nick00:
The IMAGE field contains an image in emf format. If i do ms.SaveToFile, the valid image is saved to the file.

Nick00:
I found out that the problem occurs when rendering the emf / wmf format. JPEG Rendered without problems. Attached is a test project.
https://drive.google.com/file/d/1Ee301-ej4iW25z7isH8eW37r6ksZe3P5/view?usp=share_link

Jurassic Pork:
hello,
for GDI+ you can try the GDIPlus-Library-for-Delphi-and-Lazarus. There is a package for Lazarus. Exemple :

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---implementationuses  GDIPlus; {$R *.lfm} { TForm1 } procedure TForm1.PaintBox1Paint(Sender: TObject);var img:IGPImage;    g: IGPGraphics;begin  img := TGPImage.Create('image.emf');  g:=TGPGraphics.Create(PaintBox1.Canvas.Handle);  g.SetPageUnit (UnitPixel);  g.DrawImage(img,0,0,PaintBox1.Width,PaintBox1.Height); end;      

Friendly, J.P               

Navigation

[0] Message Index

[#] Next page

Go to full version