| 属性/方法 | 说明 |
|---|---|
| Stretch | 是否根据图象自动缩放大小 |
| Picture | TPicture 对象 |
| 属性/方法 | 说明 |
|---|---|
| Bitmap | TBitmap 对象 |
| Assign(...) | 从其它对象复制图象,有: TBitmap 等 |
| Graphic | TGraphic 对象 |
| 属性/方法 | 说明 |
|---|---|
| Assign(...) | 从其它对象复制 BMP 图图象,有: TBitmap、TJpegImage 等 |
| LoadFromStream(TStream) | 从流中加载 BMP 图象 |
| Width | 宽度 |
| Height | 高度 |
| Canvas | 画布对象,进行绘图操作 |
代表一个图像,存储了图像的源码。
| 属性/方法 | 说明 |
|---|---|
| LoadFromClipboardFormat | 从剪贴板载入图像 |
| LoadFromFile | 从文件中载入图像 |
| LoadFromStream | 从流中载入图像 |
| SaveToClipboardFormat | 复制到剪贴板 |
| SaveToFile | 图像保存到文件 |
| SaveToStream | 图像保存到流 |
| LoadFromClipboardFormat(AFormat: Word; AData: THandle; APalette: HPALETTE) |
| 参数 | 说明 |
|---|---|
| AFormat | |
| AData | |
| APalette |
| 属性/方法 | 说明 |
|---|---|
| LoadFromStream(TStream) | 从流中加载 JPEG 图象 |
| PixelFormat | 设置色深,可用 jf24Bit jf8Bit |
| CompressionQuality | 设置图像存储的质量,1-100 |
| Grayscale | 是否灰度,消除颜色 在 Assign 前、LoadFrom... 后设置 |
| Palette | 调色板,TPalette 对象 |
| Performance | 优化选择,可用 jpBestQuality 和 jpBestSpeed |
| 属性/方法 | 说明 |
|---|---|
| OptimizeColorMap() | 优化颜色表(缩小存储尺寸) |
| var ok : boolean; begin adoconnection1.ConnectionString := 'driver={sql server};...'; adoquery1.SQL.Text := 'select top 1 pic from images'; adoquery1.Open; with adoquery1 do ok := ViewPicture(image1,CreateBlobStream(FieldByName('pic'),bmRead),'JPG'); if not ok then showmessage('显示图象失败!') else if image1.Stretch then begin image1.Width := image1.Picture.Width; image1.Height:= image1.Picture.Height; end; adoquery1.Close; adoconnection1.Close; end; |
// 显示图象函数 // 返回值表示图象显示是否成功 // 显示图象函数,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; |
var
bmp : TBitMap;
jpg : TJpegImage;
gif : TGifImage; // 非标准件
begin
bmp:=TBitmap.Create;
bmp.Canvas.Brush.Color:=clRed; // 背景色:红
bmp.Width:=100; // 宽度
bmp.Height:=100; // 高度
bmp.Canvas.TextOut(0,0,'1234'); // 输出文字
bmp.SaveToFile('c:\1.bmp'); // 保存为 BMP
jpg:=TJPEGimage.Create;
jpg.Assign(bmp); // 导入图像
jpg.CompressionQuality:=100; // 图像质量
jpg.Performance:=jpBestQuality; // 优化:质量
jpg.SaveToFile('c:\1.jpg'); // 保存为 JPEG(质量较差,原因待查)
gif := tgifimage.create;
gif.Assign(bmp); // 导入图像
gif.OptimizeColorMap; // 优化
gif.SaveToFile('c:\1.gif'); // 保存为 GIF
gif.Free;
image1.Picture.Bitmap.Assign(jpg); // 显示图像
bmp.Free;
jpg.Free;
gif.Free;
end; |
| // JPEG 图像,Stream 载体 ms := TMemoryStream.Create; |
| // BMP 图像,Stream 载体 ms := TMemoryStream.Create; |
| // 直接互传 image2.Picture.Assign( image1.Picture ); |