Subject Using and updating PNG's in a Blob Field
Author goldentaoca
Hi

We've recently moved to Delphi 2010 and IBO 4.9.9 and I'm getting a strange error when extracting a PNG from a Blob field.

I'm using the following code to extract it from the blob and store it in a TPicture.

if FieldByName('Logo').IsNotNull then begin
tmpStream := CreateBlobStream(FindField('Logo'), bsmRead);
try
tmpPNG := TPNGImage.Create;
tmpPNG.LoadFromStream(tmpStream);
FLogo.Assign(tmpPNG);
finally
FreeAndNil(tmpPNG);
FreeAndNil(tmpStream);
end;
end;

For reference, when I go to store it back in the blob, I'm basically just doing the opposite.

tmpStream := CreateBlobStream(FindParam('LOGO'), bsmWrite);
try
if Assigned(FLogo.Graphic) and (not FLogo.Graphic.Empty) then begin
tmpPNG := TPNGImage.Create;
tmpPNG.Assign(FLogo.Graphic);
tmpPNG.SaveToStream(tmpStream);
end
else
ParamByName('LOGO').Clear;
finally
FreeAndNil(tmpPNG);
FreeAndNil(tmpStream);
end;

The strange part is that ignoring the error everything works fine, but I'd really prefer it worked without the error below at all.

---------------------------
Debugger Exception Notification
---------------------------
Project raised exception class EPNGInvalidFileHeader with message 'The file being read is not a valid "Portable Network Graphics" image because it contains an invalid header. This file may be corrupted, try obtaining it again'.
---------------------------
Break Continue Help
---------------------------

If anyone could shed some light on what might be causing the error that'd be greatly appreciated.