Board index » delphi » I can't insert JPEG image into database with ADO

I can't insert JPEG image into database with ADO

I can't insert JPEG image into database with ADO.I can insert only BMP
image.

 Please help me.
Thanks.

 

Re:I can't insert JPEG image into database with ADO


Quote
"Hristo" <hri...@isinc.org> wrote in message news:3a956c19_2@dnews...
> I can't insert JPEG image into database with ADO.I can insert only BMP
> image.

I haven't worked much with ADO myself, but I think one solution is as
follows:

1. Load the image into a stream (such as TMemoryStream).
2. Convert the stream into a variant array of byte.
3. Store the variant into the database.
You can use the routines below to convert between variants and any decendent
of TStream.

function StreamToVariant(const Stream: TStream): OleVariant;

var
  P: Pointer;

begin
  Result := VarArrayCreate([0, Stream.Size - 1], varByte);
  Stream.Position := 0;

  P := VarArrayLock(Result);
  try
    Stream.Read(P^, Stream.Size);
  finally
    VarArrayUnlock(Result);
  end;
end;

procedure VariantToStream(const V: OleVariant;
                          const Stream: TStream);

var
  P: Pointer;
  L: Integer;

begin
  Assert(VarType(V) = varByte or varArray);
  Assert(VarArrayDimCount(V) = 1);

  L := VarArrayHighBound(V, 1) - VarArrayLowBound(V, 1) + 1;
  Stream.Size := L;
  Stream.Position := 0;

  P := VarArrayLock(V);
  try
    Stream.Write(P^, Stream.Size);
  finally
    VarArrayUnlock(V);
  end;
end;

Re:I can't insert JPEG image into database with ADO


Thanks... I wil try it!!
G. Williams <no mail please> wrote in message news:3a956fa5$1_2@dnews...

Re:I can't insert JPEG image into database with ADO


 It is not working.
 Delphi return to me exception like 'Bitmap image is not valid'.
 My blob field is ftBlob.
 I can't got where is the problem.
Quote
Hristo <hri...@isinc.org> wrote in message news:3a957199_1@dnews...

Re:I can't insert JPEG image into database with ADO


Quote
"Hristo" <hri...@isinc.org> wrote in message news:3a962f82_2@dnews...
> It is not working.
>  Delphi return to me exception like 'Bitmap image is not valid'.

At what point is this exception generated?  When writing to the table, or
reading from it?

Quote
>  My blob field is ftBlob.
>  I can't got where is the problem.

If you intend to store both bitmap and jpeg images in the same field, then
you'll also still have to handle the differences between bitmaps and jpegs
yourself when reading data back out of the table, and you should create a
new field that simply indicates the type of graphic that's stored in the
variant field.

It seems like either your code or a data-aware control somewhere is assuming
that the field only contains bitmap data.

Re:I can't insert JPEG image into database with ADO


Are you using TDBImage?  If so, throw it away, and use TImage.  Use
streams to read and write from the database blob field.
Quote
Hristo wrote:
> I can't insert JPEG image into database with ADO.I can insert only BMP
> image.

>  Please help me.
> Thanks.

Re:I can't insert JPEG image into database with ADO


Thanks for help .I'm using TImage to insert JPEG in database and everything
is OK.

Other Threads