世界上的人都可以将bmp转换为jpg,为什么我不可以??????????????????

bphantom 2003-09-28 04:03:52
procedure TForm1.Button1Click(Sender: TObject);
var
theJpeg : TJPEGImage ;
//thebmp : TBitmap;
theImage: TImage;
begin
theJpeg := TJpegImage.Create;
//thebmp := TBitmap.Create;
theImage:= TImage.Create(self);

try
with theJpeg do
begin
theImage.Picture.Bitmap.LoadFromFile('C:\Car.bmp');
Assign(theImage.Picture.Bitmap);
CompressionQuality:=StrToInt('75');
Compress;
SaveToFile('c:\Car.JPG');
end;
finally
theJpeg.Free;
theImage.Free;
end;

{
try
thebmp.LoadFromFile('C:\Car.bmp');
theJpeg.Assign(thebmp);
theJpeg.CompressionQuality:=StrToInt('75');
theJpeg.Compress;
theJpeg.SaveToFile('C:\Car.jpg');
finally
thebmp.Free;
theJpeg.Free;
end;}

end;
Delphi中的源程序都是类似我这样的,如下:
procedure TForm1.Button1Click(Sender: TObject);

var
jp: TJPEGImage; //Requires the "jpeg" unit added to "uses" clause.
begin
jp := TJPEGImage.Create;
try
with jp do
begin
Assign(Image1.Picture.Bitmap);
SaveToFile('c:\oneeye.jpg')
end;
finally
jp.Free;
end;
end;
错误提示是:“Cannot assign a TBitmap to a TJPEGImage”.
我到底做错了什么?要这样惩罚我。
...全文
63 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingice 2003-10-08
  • 打赏
  • 举报
回复
?
bphantom 2003-09-30
  • 打赏
  • 举报
回复
Fuck,我从新建个工程,考入代码,现在就可以了,一摸一样的代码,我晕。且'C:\Car.bmp'是一直都存在的。
lizexia 2003-09-29
  • 打赏
  • 举报
回复
delphi卸载重装 说不定可以啊!
aiirii 2003-09-29
  • 打赏
  • 举报
回复
你的写法有问题,用如下代码!
Jpg:TJpegImage;Bmp:Tbitmap;
if Opendialog1.Filename<>'' then
begin
Bmp:=TBitmap.Create;
Bmp.LoadFromFile(Opendialog1.FileName);
Image1.Picture.LoadFromFile(Opendialog1.FileName);
end;

if Savedialog1.filename<>'' then
begin
Jpg:=TJpegImage.Create;
Jpg.Assign(Bmp);
Jpg.CompressionQuality:=StrToInt(Edit1.Text);
Jpg.Compress;
Jpg.SaveToFile(Savedialog1.FileName);
Jpg.Free;
end;
bphantom 2003-09-28
  • 打赏
  • 举报
回复
theImage和thebmp都是空的。
mmtang3 2003-09-28
  • 打赏
  • 举报
回复
是否要现将bmp存到内存流中,然后再到入到theJpeg中。
lxl 2003-09-28
  • 打赏
  • 举报
回复
代码没错啊,我也是这样用过的,检查一下是否IMAGE有内容?

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧