Recent

Author Topic: Lazarus GDI+ problem. Access Violation  (Read 2988 times)

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: Lazarus GDI+ problem. Access Violation
« Reply #15 on: May 04, 2023, 08:53:44 am »
Can you upload a sample image?
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Nick00

  • New member
  • *
  • Posts: 8
Re: Lazarus GDI+ problem. Access Violation
« Reply #16 on: May 04, 2023, 08:56:55 am »
Change the extension to emf.

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: Lazarus GDI+ problem. Access Violation
« Reply #17 on: May 04, 2023, 12:38:32 pm »
When I save the stream objects it creates in its two methods in a file, they both have the same content. When I reset the starting positions, the result is still the same. I think it's an interesting situation.
There is probably information that the stream object created by the Adapter class has or does not have, other than the context data.
In the future, I will investigate this issue in depth. I have different trials in mind, but that's all I've got at the moment.
I would be glad if experts on the subject give their opinion.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11446
  • FPC developer.
Re: Lazarus GDI+ problem. Access Violation
« Reply #18 on: May 04, 2023, 12:56:44 pm »
I also want to have a look in time. Can sb create a bugreport with image, code and link to gdiplus units?

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: Lazarus GDI+ problem. Access Violation
« Reply #19 on: May 05, 2023, 08:50:00 am »
I don't know why, but some issues are stuck in my head. This is one of them, the opinion that I have reached from the research I have done;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ButtonAPClick(Sender: TObject);
  2. var
  3.     img:IGPImage;
  4.     g: IGPGraphics;
  5.     Ms:TMemoryStream;
  6.     Adapter:TStreamAdapter;
  7.     EmfStream :IStream;
  8.     test:Qword;
  9. begin
  10.   Ms:=TMemoryStream.Create;
  11.   Ms.LoadFromFile(efp);
  12.   Ms.Position:=0;
  13.  
  14.   Adapter:=TStreamAdapter.Create(ms);
  15.  
  16.   EmfStream:=Adapter as IStream; // Not the adapter class, the conversion metedo here is doing the wrong thing.
  17.  
  18.   img := TGPImage.Create(EmfStream);
  19.   g:=TGPGraphics.Create(Image1.Canvas.Handle);
  20.   g.SetPageUnit (UnitPixel);
  21.   g.DrawImage(img,0,0,Image1.Width,Image1.Height);
  22. end;
  23.  

If we make the above "EmfStream:=Adapter as IStream;" method ourselves. We can see that the problem is fixed.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ButtonAPClick(Sender: TObject);
  2.     function AdapterStreamtoIStream(const AStream: TStream): IStream;
  3.     var
  4.       Output: IStream;
  5.       MemoryPointer: Pointer;
  6.       test:Qword;
  7.       begin
  8.         try
  9.           GetMem(MemoryPointer, AStream.Size);
  10.           try
  11.             AStream.ReadBuffer(MemoryPointer^, AStream.Size);
  12.           except
  13.             FreeMem(MemoryPointer);
  14.             raise;
  15.           end;
  16.         finally
  17.         end;
  18.  
  19.         CreateStreamOnHGlobal(0, True, Output);
  20.         try
  21.           Output.Write(MemoryPointer, AStream.Size, nil);
  22.           Output.Seek(0, STREAM_SEEK_SET, test);
  23.           Result := Output;
  24.         except
  25.           Output := nil;
  26.           raise;
  27.         end;
  28.     end;
  29. var
  30.     img:IGPImage;
  31.     g: IGPGraphics;
  32.     Ms:TMemoryStream;
  33.     Adapter:TStreamAdapter;
  34.     EmfStream :IStream;
  35.     test:Qword;
  36. begin
  37.   Ms:=TMemoryStream.Create;
  38.   Ms.LoadFromFile(efp);
  39.   Ms.Position:=0;
  40.  
  41.   Adapter:=TStreamAdapter.Create(ms);
  42.  
  43.   EmfStream:=AdapterStreamtoIStream(Adapter.Stream);  //This code gives the impression that the adapter class is working correctly.
  44.  
  45.   img := TGPImage.Create(EmfStream);
  46.   g:=TGPGraphics.Create(Image1.Canvas.Handle);
  47.   g.SetPageUnit (UnitPixel);
  48.   g.DrawImage(img,0,0,Image1.Width,Image1.Height);
  49. end;
  50.  

This is my last post on the subject.  ;D
« Last Edit: May 05, 2023, 08:53:29 am by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018