0

I have to load a jpeg file into OleGrafic. When I call OleGraphic.LoadFromStream(), it raises OLE Error 800A01E1.

I tried to identify this error, without any success. The closest answer related to ole errors was List of all OLE error codes but I can not find 800A01E1 there.

I tried also to initialize Ole in main form. Same form that is generating this error. Without any success.

initialization
  OleInitialize(nil);
finalization
  oleuninitialize;

@ Remy Lebeau: This code worked proper in other projects:

sFileName := OPD.FileName; 
      OleGraphic := TOleGraphic.Create; 
      fs := TFileStream.Create(sFileName, fmOpenRead Or fmSharedenyNone);
     // fs.Seek(0,soFromBeginning);// := 0;  Here I  tried to make sure it's o.
      OleGraphic.LoadFromStream(fs);
      Source := TImage.Create(Nil);
      Source.Picture.Assign(OleGraphic);
      SrcBild := TBitmap.Create; 
      SrcBild.Width := Source.Picture.Width;
      SrcBild.Height := Source.Picture.Height;
      SrcBild.Canvas.Draw(0, 0, Source.Picture.Graphic);
      DstBild := TBitmap.Create;
      DstBild.Width := 200;
      DstBild.Height := 100;
      SmoothResize(SrcBild, DstBild);

SmoothResize is from http://www.swissdelphicenter.com/torry/showcode.php?id=1896

Community
  • 1
  • 1
Vladds7
  • 81
  • 15
  • 2
    When searching for such 8-digit hex error codes for Windows, just prefix `0x` in front and do a search, giving me this: http://stackoverflow.com/questions/6668147/when-reading-a-cursor-from-a-resources-file-an-argumentexception-is-thrown - CTL_E_INVALIDPICTURE – Lasse V. Karlsen Jul 25 '14 at 15:01
  • Yes. That was, InvalidPicture. Thank you for the prefix information. If you would like to make it an answer. http://msdn.microsoft.com/en-us/library/ms919477.aspx – Vladds7 Jul 25 '14 at 15:13
  • Posted it as an answer. – Lasse V. Karlsen Jul 25 '14 at 15:18
  • 1
    Please show your actual code. What stream are you passing to OleGraphic? Where does the stream come from? Is its Position in the right place? Are you sure the stream contains a JPG, with a valid JPG header? – Remy Lebeau Jul 25 '14 at 16:11
  • @ Remy Lebeau: Added. The Jpg file I used was corrupted. – Vladds7 Jul 25 '14 at 20:06

2 Answers2

2

I cannot tell you why that image fails to load, but I can tell you the name of that error code, and how to find such codes in the future.

8-digit hexadecimal exception/hresult error codes in Windows can usually be found by prefixing them with 0x, in this case giving 0x800A01E1.

A simple search for that tells me that the name of that error code is CTL_E_INVALIDPICTURE, and that result is also listed on the underlying Win32 function, OleLoadPictureFile:

Return value

This method returns standard COM error codes in addition to the following values.
Return code           Description
S_OK                  The method completed successfully.
CTL_E_INVALIDPICTURE  Invalid picture file.

Of course, that doesn't tell you what is wrong either, but at least you now know that the likely source is the actual content of the file.

Since the documentation for the function also lists valid file formats, my guess would be to first ensure the file is one of those formats, and not just some other image file (or random data for that matter) masquerading as a JPEG or something under an incorrect filename, and then try to load that file up into some other program. Perhaps you can even just load and save the file in some tool that can rewrite the contents of image files, might fix it.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • `TOleGraphic.LoadFromStream()` uses [`OleLoadPicture()`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms693724.aspx), not `OleLoadPictureFile()`. – Remy Lebeau Jul 25 '14 at 16:48
1

TOleGraphic.LoadFromStream() uses OleLoadPicture() internally. According to its documentation:

The stream must be in BMP (bitmap), WMF (metafile), or ICO (icon) format.

In other words, JPG is not supported.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770