Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   objeto ole (https://www.clubdelphi.com/foros/showthread.php?t=4827)

omy 29-10-2003 22:27:27

objeto ole
 
Hola.

tengo una bd y uno de sus campos es un campo ole, que contiene una fotos. como puedo hacer que mi formulario pueda ver la foto ?????????
stream, me mensiono un amigo, pero no me quedo claro como funciona.

Gracias:(

marcoszorrilla 30-10-2003 08:34:12

En un principio te podría servir con un DbImage, conectado al campo, pero todo depende de que tipo de base de datos utilices y como se haya almacenado la imagen.

Un Saludo.

omy 31-10-2003 18:18:42

Gracias, de antemano.. la cuestion mas clara es.

es una bd en acces el campo se llama foto, y es de tipo ole.


¿Como puedo ver la foto?

En el dbimage, no encontre la forma.

Descendents 31-10-2003 18:51:21

Te da error o que te pasa con el dbimage?

Te lo digo porque a mi no me acuerdo que me paso hace tiempo, pero se que tuve problemas con dbimage.

Me parece, que el dbimage solo acepta BMPs y no GIFs ni JPGs i menos TIFF ni nada.

omy 31-10-2003 22:25:16

Descendents, me marca un error en tiempo de diseño, no puedo ligarlos, cierto no es compatible, solo acepta los que tu comentastes.


mi idea era meter el contenido de el campo foto a un dbedit despues igualar un objeto ole al dbedit pero no puedo...

marcoszorrilla 31-10-2003 23:13:56

Léete esta información:

RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To

Pictures inside a database
Page 4: Seeking the start of Jpeg in the BLOB.
More of this Feature
• Page 1: BLOBs in Access
• Page 2: DBImage.NOT
• Page 3: Streaming JPG
• Page 5: Project's Code

Printer friendly versionPrinter friendly version
Join the Discussion
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
Related Resources
• free DB Course.TOC
• Delphi DB articles


OLE object type format - take three!
All this leaves us with nothing but to store the picture to a disk (as an ordinary binary file) and see what's inside it.
One nice thing with picture files (formats) is that all have some header that uniquely identifies the image. The JPG picture file starts with the, so called, SOI marker that has the value of $FFD8 hex.

This next line of code stores the value of the Picture field to a file (BlobImage.dat) in the working directory. Assign this code in the OnCreate event for the form, start the project and remove the code.

ADOTable1Picture.SaveToFile('BlobImage.dat');

Once we have the file, we can use some Hex editor to see it's content.

Jpeg as OLE object binary file

Would you believe this! MS Access stores the path of a linked OLE object as part of the object's definition in the OLE object field. Because the definition of OLE object storage is not documented (!? this is straight from MS) there is no way to know what gets written before the actual image data.

Think about this twice. First: we'll need to seek to the 'FFD8' and read the image from there. Second, the 'FFD8' might not always be at the same position in the file. Conclusion: we need a function that returns the position of the SOI marker for the JPG file stored as OLE object in an Access database.

The correct way - take four!
Provided with the Blob type field our function should return the position of the 'FFD8' string inside the ADOBlobStream. The ReadBuffer reads byte by byte from the stream. Each call to ReadBuffer moves the position of the stream by one. When two bytes together (as hex values) result in SOI marker the function returns the stream position. This is the function:

Código:

function JpegStartsInBlob
        (PicField:TBlobField):integer;
var
 bS    : TADOBlobStream;
 buffer : Word;
 hx    : string;
begin
 Result := -1;
 bS := TADOBlobStream.Create(PicField, bmRead);
 try
  while (Result = -1) and
        (bS.Position + 1 < bS.Size) do
  begin
  bS.ReadBuffer(buffer, 1);
  hx:=IntToHex(buffer, 2);
  if hx = 'FF' then begin
    bS.ReadBuffer(buffer, 1);
    hx:=IntToHex(buffer, 2);
    if hx = 'D8' then Result := bS.Position - 2
    else if hx = 'FF' then
              bS.Position := bS.Position-1;
  end; //if
  end; //while
 finally
  bS.Free
 end;  //try
end;

Once we have the position of the SOI marker we use it to seek to it in the ADOBlob stream.

uses jpeg;
...
procedure TForm1.btnShowImageClick(Sender: TObject);
var
  bS  : TADOBlobStream;
  Pic : TJpegImage;
begin
  bS := TADOBlobStream.Create
        (AdoTable1Picture, bmRead);
  try
    bS.Seek(JpegStartsInBlob(AdoTable1Picture),
            soFromBeginning);
    Pic:=TJpegImage.Create;
    try
    Pic.LoadFromStream(bS);
    ADOImage.Picture.Graphic:=Pic;
    finally
    Pic.Free;
    end;
  finally
    bS.Free
  end;
end;

Un saludo.

omy 05-11-2003 18:15:54

gracias, ya casi entendi todo el codigo, pero tengo problemas..

procedure TForm1.btnShowImageClick(Sender: TObject);
var
bS : TADOBlobStream;
Pic : TJpegImage;
----(1) AdoTable1Picture : TBlobField; -----
begin
---(2) bS := TADOBlobStream.Create (AdoTable1Picture, bmRead);



(1) creo el objeto TBlobField
(2)Cuando quiere leer el objeto me marca error con la bd de access

Access violation at address 004A09AD in module ' Project1.exe' Read of adress 0000009D

¿Puede ser el motor de con la que galo access, uso el Jet 4?


La franja horaria es GMT +2. Ahora son las 16:48:34.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi