注册 登录
编程论坛 Delphi论坛

如何将ACCESS的OLE对象字段存储的BMP图象显示出来

学而优则仕 发布于 2005-08-28 22:37, 3384 次点击
    在ACCESS表中将BMP图象通过插入对象的方式存储于OLE对象字段,现在的问题是如何将图象显示出来,我用的是ADO。谢谢
4 回复
#2
学而优则仕2005-09-02 18:26
这个问题很难吗?
    这个问题很难吗?这么长时间没人帮我,呜呼!!!
#3
makebest2005-09-07 15:02
的确很难啊,显示这个图像需要许多其他知识。给你一点提示,看你是不是能够消化:
// 显示图象函数
// 返回值表示图象显示是否成功
// 显示图象函数,pictype 可为:'BMP' 'JPG' 'JPEG'
function ViewPicture(img:TImage; query:TADOQuery; fieldname:String; pictype:String):boolean;
var
    jpg : TJpegImage;
    ts  : TStream;
    gif : TGifImage;
begin
    result := false;

    pictype := LowerCase(pictype);
    try
        ts := query.CreateBlobStream(query.FieldByName(fieldname),bmRead);
        if ts.Size=0 then exit;

        if (pictype='bmp') or (pictype='image/bmp')  then
        begin
            try
                img.Picture.Bitmap.LoadFromStream(ts);
                result := true;
            except
            end;
        end;

        if (pictype='jpg') or (pictype='image/pjpeg') then
        begin
            jpg := TJpegImage.Create;
            try
                jpg.LoadFromStream(ts);
                img.Picture.Bitmap.Assign(jpg);
                result:=true;
            finally
                jpg.Free;
            end;
        end;

        if (pictype='gif') or (pictype='image/gif') then
        begin
            gif := TGifImage.Create;
            try
                gif.LoadFromStream(ts);
                img.Picture.Bitmap.Assign(gif);
                result:=true;
            finally
                gif.Free;
            end;
        end;

        ts.Free;

    except end;
end;

[此贴子已经被作者于2005-9-7 15:03:16编辑过]

#4
学而优则仕2005-09-08 18:22
谢谢,解决了
    谢谢你的指教,问题已经解决。
#5
学而优则仕2005-09-11 19:15
我的delphi中怎么没有TGifImage?
以下是引用makebest在2005-9-7 15:02:10的发言: 的确很难啊,显示这个图像需要许多其他知识。给你一点提示,看你是不是能够消化:
// 显示图象函数
// 返回值表示图象显示是否成功
// 显示图象函数,pictype 可为:'BMP' 'JPG' 'JPEG'
function ViewPicture(img:TImage; query:TADOQuery; fieldname:String; pictype:String):boolean;
var
    jpg : TJpegImage;
    ts  : TStream;
    gif : TGifImage;
begin
    result := false;

    pictype := LowerCase(pictype);
    try
        ts := query.CreateBlobStream(query.FieldByName(fieldname),bmRead);
        if ts.Size=0 then exit;

        if (pictype='bmp') or (pictype='image/bmp')  then
        begin
            try
                img.Picture.Bitmap.LoadFromStream(ts);
                result := true;
            except
            end;
        end;

        if (pictype='jpg') or (pictype='image/pjpeg') then
        begin
            jpg := TJpegImage.Create;
            try
                jpg.LoadFromStream(ts);
                img.Picture.Bitmap.Assign(jpg);
                result:=true;
            finally
                jpg.Free;
            end;
        end;

        if (pictype='gif') or (pictype='image/gif') then
        begin
            gif := TGifImage.Create;
            try
                gif.LoadFromStream(ts);
                img.Picture.Bitmap.Assign(gif);
                result:=true;
            finally
                gif.Free;
            end;
        end;

        ts.Free;

    except end;
end;
1