我在向access数据库中存图片时发现只能存bmp格式的
请给出代码谢谢

解决方案 »

  1.   

    function Bmp2JPG(BmpFileName,JPGFileName:string;CompressRate:integer=86):boolean;
    將BMP圖檔轉為JPG圖檔,BMP檔名為BmpFileName,JPG檔名為JPGFileName,CompressRate為JPG圖檔的壓縮率,若不傳入此參數內定為86%壓縮率.function JPG2BMP(JPGFileName,BmpFileName:string):boolean;
    將JPG圖檔轉為BMP圖檔,JPG檔名為JPGFileName,BMP檔名為BmpFileNamefunction Bmp2JPG(BmpFileName,JPGFileName:string;CompressRate:integer=86):boolean;
    var jpg:TJPEGImage;
        bmp:tBitMap;
    begin
      jpg:=TJPEGImage.create;
      bmp:=TBitMap.create;
      result:=true;
      try
        bmp.LoadFromFile(BmpFileName);
        jpg.assign(bmp);
        jpg.CompressionQuality:=CompressRate;
        jpg.SaveToFile(JPGFileName);
      except
        result:=false;
      end;
      jpg.free;
      bmp.free;
    end;
    function JPG2BMP(JPGFileName,BmpFileName:string):boolean;
    var jpg:TJPEGImage;
        bmp:tBitMap;
    begin
      jpg:=TJPEGImage.create;
      bmp:=TBitMap.create;
      result:=true;
      try
        jpg.loadfromfile(JPGFileName);
        bmp.assign(jpg);
        bmp.SaveToFile(BmpFileName);
      except
        result:=false;
      end;
      jpg.free;
      bmp.free;
    end;
      

  2.   

    >>我在向access数据库中存图片时发现只能存bmp格式的应该是你操作有误,可以存jpg的
      

  3.   

    http://www.delphibbs.com/keylife/iblog_show.asp?xid=8023
      

  4.   

    这是我向数据库中直接存jpg文件的代码,运行时报无效位图长度错误。各位看一下问题何在。if extractfileext(s)='.jpg' then begin
          showmessage('j');
          M_Jpeg.LoadFromFile(s);
        
         
          M_Jpeg.SaveToStream(MS_JpegStream);
      
          image2.Picture.Assign(M_Jpeg);
          showmessage('ting');
          table1.Edit;
          TBlobField(table1.FieldByName('graph')).LoadFromStream(MS_JpegStream);
          table1.Post;
    end;
      

  5.   

    procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      Jpeg:TJpegImage;
      bmp:TBitmap;
    begin
       bmp:=TBitmap.Create;
       jpeg:=TJpegImage.Create;   jpeg.LoadFromFile('c:\aa.jpg');
        
       bmp.Assign(jpeg);   ADOQuery1.Insert;
       TBlobField(ADOQuery1.FieldByName('Image')).Assign(bmp);
       ADOQuery1.Post;   bmp.Free;
       jpeg.Free;
    end;
      

  6.   

    问题是转化无错但是当进行数据库操作时,系统提示 invalid bitmap!!!!
      

  7.   

    转化很简单的,用image来load一个jpg,image再save,就是bmp的了