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”.
我到底做错了什么?要这样惩罚我。

解决方案 »

  1.   

    代码没错啊,我也是这样用过的,检查一下是否IMAGE有内容?
      

  2.   

    是否要现将bmp存到内存流中,然后再到入到theJpeg中。
      

  3.   

    delphi卸载重装  说不定可以啊!
      

  4.   

    你的写法有问题,用如下代码!
    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;
      

  5.   

    Fuck,我从新建个工程,考入代码,现在就可以了,一摸一样的代码,我晕。且'C:\Car.bmp'是一直都存在的。