TBitmap是delphi的一个什么类?显示Jpeg格式的图片的变量相应的类是什么?
比如:procedureTForm1.Button1Click(Sender:TObject);varMyCanvas:TControlCanvas;bitmap:TBi...
比如:
procedure TForm1.Button1Click(Sender: TObject);
var
MyCanvas : TControlCanvas;
bitmap : TBitmap;
Begin
bitmap:=TBitmap.Create;
......
end;
bitmap变量可用于显示bmp格式图片,若声明一个变量用来显示jpeg格式的呢?盼高人指点迷津! 展开
procedure TForm1.Button1Click(Sender: TObject);
var
MyCanvas : TControlCanvas;
bitmap : TBitmap;
Begin
bitmap:=TBitmap.Create;
......
end;
bitmap变量可用于显示bmp格式图片,若声明一个变量用来显示jpeg格式的呢?盼高人指点迷津! 展开
1个回答
展开全部
uses
jpeg;
用法
var tupian:tjpegimage;
用法例子
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DB, ADODB, StdCtrls,jpeg, Buttons;
type
TForm1 = class(TForm)
selectimage: TButton;
Button2: TButton;
ADOTable1: TADOTable;
Image1: TImage;
openpicturedialog1: TOpenDialog;
Image2: TImage;
Image3: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure selectimageClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
function newid():integer;
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.selectimageClick(Sender: TObject);
begin
if openpicturedialog1.Execute then
image1.Picture.LoadFromFile(openpicturedialog1.FileName );
end;
function Tform1.newid:integer;
var
maxid:integer;
begin
with form1.adoquery1 do
begin
close;
sql.clear;
sql.add('select max(id)+1 as newmax from test');
open;
end;
maxid:=form1.ADOQuery1.fieldbyname('newmax').AsInteger;
result:=maxid;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
adotable1.Open;
adotable1.Append;
adotable1.Edit ;
adotable1.FieldByName('myimage').Assign(image1.Picture.Graphic);
//以下记录保存到数据库的图像格式
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件扩展名
if uppercase(ext) = '.BMP' THEN
begin
adotable1.FieldByName('isbmp').VALUE := 1; //BMP型图像数据
adotable1.FieldByName('id').Value:=newid;
end
ELSE IF (UPPERCASE(EXT) = '.JPEG') OR (UPPERCASE(EXT) = '.JPG') THEN
begin
adotable1.FieldByName('isbmp').VALUE := 0; //JPEG型图像数据
adotable1.FieldByName('id').Value:=newid;
end;
ADOTABLE1.Post ;
end;
image2.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
if adotable1.fieldbyname('isbmp').Asstring = '1' then //BMP型图像数据
image2.Picture.bitmap.Assign(adotable1.fieldbyname('myimage'))
//上边语句中的bitmap不能为graphic,否则会出错
else if adotable1.fieldbyname('isbmp').asstring = '0' then //JPEG型图像数据
begin //begin2
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image2.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
end; //end begin2
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
adotable1.Open;
adotable1.Next;
image3.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image3.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
if adotable1.Eof then
adotable1.First;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
adotable1.Open;
if adotable1.Bof then
adotable1.Last
else
adotable1.Prior;
image3.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image3.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
adotable1.Delete
end;
end.
jpeg;
用法
var tupian:tjpegimage;
用法例子
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DB, ADODB, StdCtrls,jpeg, Buttons;
type
TForm1 = class(TForm)
selectimage: TButton;
Button2: TButton;
ADOTable1: TADOTable;
Image1: TImage;
openpicturedialog1: TOpenDialog;
Image2: TImage;
Image3: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
procedure selectimageClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
function newid():integer;
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.selectimageClick(Sender: TObject);
begin
if openpicturedialog1.Execute then
image1.Picture.LoadFromFile(openpicturedialog1.FileName );
end;
function Tform1.newid:integer;
var
maxid:integer;
begin
with form1.adoquery1 do
begin
close;
sql.clear;
sql.add('select max(id)+1 as newmax from test');
open;
end;
maxid:=form1.ADOQuery1.fieldbyname('newmax').AsInteger;
result:=maxid;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
adotable1.Open;
adotable1.Append;
adotable1.Edit ;
adotable1.FieldByName('myimage').Assign(image1.Picture.Graphic);
//以下记录保存到数据库的图像格式
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件扩展名
if uppercase(ext) = '.BMP' THEN
begin
adotable1.FieldByName('isbmp').VALUE := 1; //BMP型图像数据
adotable1.FieldByName('id').Value:=newid;
end
ELSE IF (UPPERCASE(EXT) = '.JPEG') OR (UPPERCASE(EXT) = '.JPG') THEN
begin
adotable1.FieldByName('isbmp').VALUE := 0; //JPEG型图像数据
adotable1.FieldByName('id').Value:=newid;
end;
ADOTABLE1.Post ;
end;
image2.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
if adotable1.fieldbyname('isbmp').Asstring = '1' then //BMP型图像数据
image2.Picture.bitmap.Assign(adotable1.fieldbyname('myimage'))
//上边语句中的bitmap不能为graphic,否则会出错
else if adotable1.fieldbyname('isbmp').asstring = '0' then //JPEG型图像数据
begin //begin2
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image2.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
end; //end begin2
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
adotable1.Open;
adotable1.Next;
image3.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image3.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
if adotable1.Eof then
adotable1.First;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
ext:string;
jpegimage:tjpegimage;
begin
adotable1.Open;
if adotable1.Bof then
adotable1.Last
else
adotable1.Prior;
image3.Picture.Graphic :=nil;
//下边BMP、JPEG两种图像数据必需分别处理
//adotable1.Last;
jpegimage := tjpegimage.Create ; //通过jpegimage将图像显示在image1,否则会出错
try
jpegimage.Assign(adotable1.fieldbyname('myimage'));
image3.Picture.Graphic :=jpegimage;
finally
jpegimage.Free ;
end; //end try
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
adotable1.Delete
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询