Imagenes en una BD Access

Hola, quisiera preguntar, como es que le hago para trabajar almacenando, borrando,etc. Imagenes a y desde una base de datos access. Si existiera la posibilidad de enviarme un pequeño ejemplo. Gracias
Respuesta
1
Te envío algo útil sobre lo que demandas, insertar y extraer una imagen de BD Access:
//Carefull: the table must be in edit mode....
Procedure SaveBlobImage( aBlobField:TBlobField; Picture:TPicture );
var
Stream,Stream2:TMemoryStream;
PictureClass:String;
Size:Integer;
begin
Stream:=TMemoryStream.Create;
try
aBlobField.Clear;
PictureClass := Picture.Graphic.ClassName; //<-- here i get the
classname
Size:=Length(PictureClass);
Stream.WriteBuffer(Size,4);
if Size>0 then
Stream.WriteBuffer(PictureClass[1],Size); //<-- i write a string
containing the graphic classname
{
Here i use stream2 to store the graphic.. because some graphic classes
move the stream position!..
}
Stream2:=TMemoryStream.Create;
try
Picture.Graphic.SaveToStream(Stream2);
Stream2.Seek(0,soFromBeginning); //<-- some classes moves the stream
to beginning!(wmf's)
Size:=Stream2.Size;
Stream.WriteBuffer( Size, 4);
if Size>0 then
Stream.CopyFrom(Stream2,Size); //<-- Store the image...
finally
Stream2.Free;
end;
aBlobField.LoadFromStream(Stream); //<-- store it in the database!
finally
Stream.Free;
end;
end;
Procedure LoadBlobImage( Picture:TPicture; aBlobField:TBlobField );
var
Stream,Stream2:TMemoryStream;
PictureClass:String;
Size:Integer;
Graphic:TGraphic;
GraphicClass:TGraphicClass;
begin
Stream:=TMemoryStream.Create;
try
Stream.ReadBuffer(Size,4);
SetLength(PictureClass,Size);
if Size>0 then
Stream.ReadBuffer(PictureClass[1],Size); //<-- read the string
containing the graphic classname
Stream.ReadBuffer(Size,4); //Get the size of the image...
GraphicClass:=TGraphicClass( FindClass(PictureClass) ); //From the
string get the class
if (GraphicClass<>nil)and(Size>0) then begin
Graphic:=GraphicClass.Create; //Carefull with delphi < version 6 , the
constructor will not be called!
Stream2:=TMemoryStream.Create;
try
Stream2.CopyFrom(Stream,Size); //Read the image
Stream2.Seek(0,soFromBeginning);
{If u dont have delphi 6, this will raise an exception with
TGifImage.}
Graphic.LoadFromStream(Stream2);
finally
Stream2.Free;
end;
Picture.Assign(Graphic); //<-- store it in the database!
end;
finally
Stream.Free;
end;
end;
Disculpa, la demora, es que he estado muy ocupado, tu respuesta fue buena, pero no pude hacerlo, sin embargo, solucione mi problema de otra manera.
creas un TImage(ImgFoto), alli cargas una imagen, despues para ingresarla a la base de datos, escribes una linea
Tabla.FieldbyName('Foto').Assign(ImgFoto.Picture);
Esto tambien resulta, el unico problema es que solo me cargaron las *.bmp.
Aun no he probado bien tu codigo, he estado ocupado, apenas tenga un tiempito lo pruebo bien, y te escribo si me resulto.por mientras dare por terminada la respuesta. y gracias.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas