图片转换和读取(个人笔记)

uses
Jpeg


procedure BitmapToJpeg(Bitmap: TBitmap; Jpg: TJPEGImage;
  Compress: Integer);
begin
  Jpg.Assign(Bitmap);
  if Compress>0 then
  begin
    Jpg.CompressionQuality:= Compress;
    Jpg.Compress;
  end;
end;


procedure JpegToBitmap(Jpg: TJPEGImage; Bitmap: TBitmap);
begin
  Bitmap.Width:= JPG.Width;
  Bitmap.Height:= JPG.Height;
  Bitmap.PixelFormat:= pf24bit;
  Bitmap.Canvas.Draw(0,0,JPG);
end;

 

var
  ms:TMemoryStream;
  jpg:TJPEGImage;
with ADOQuery3 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('exec GetImage ''' + ADOQuery2.FieldByName('IDBName').AsString + ''',''' + ADOQuery2.FieldByName('IUID').AsString + '''');
      Open;
      if not IsEmpty then
      begin
        ms:= TMemoryStream.Create;
        jpg:= TJPEGImage.Create;
        try
          TBlobField(FieldByName('Image')).SaveToStream(ms);
          ms.Position:=0;
          jpg.LoadFromStream(ms);
          JpegToBitmap(jpg, Image1.Picture.Bitmap);
        finally
          ms.Free;
          jpg.Free;
        end;
      end;
      Close;
    end;

你可能感兴趣的:(图片)