我的源文件为256级灰度,经历了上述转化后出来的jpeg却是24b的,怎么我限定了最后的jpeg为jp8bit但是图象不正常(无信息),应该是格式不对,但我限定bmp为bp8bit,可是最后得到的jpeg还是24b的。请问我要怎么办啊

解决方案 »

  1.   

    use jpeg; 
    var
      MyJpeg: TJpegImage;
      Image1: TImage;
    begin
      Image1:= TImage.Create(self);
      MyJpeg:= TJpegImage.Create;
      Image1.Picture.Bitmap.LoadFromFile('c:.BMP'); // Load the Bitmap from a file
      MyJpeg.Assign(Image1.Picture.Bitmap); // Assign the BitMap to MyJpeg object
      MyJpeg.CompressionQuality:=StrToInt('75');
      MyJpeg.Compress;
      MyJpeg.SaveToFile('c:.JPG'); // Save the JPEG to Disk
    end;var
      MyJpeg: TJpegImage;
      bmp: Tbitmap;
    begin
      bmp:=tbitmap.Create;
      MyJpeg:= TJpegImage.Create;
      myjpeg.LoadFromFile('c:.jpg');
      bmp.Assign(myjpeg);
      bmp.SaveToFile('c:.bmp'); // Save the JPEG to Disk
    end;
      

  2.   

    感谢dext(德克斯特)前辈,这个方法不错的
      

  3.   

    use jpeg;**********************(  jpeg to  bmp  )*****************************
    procedure Tfrm_Probation.bsSkinButton5Click(Sender: TObject);
    var
      ImageBMP:Tbitmap;
      ImageJPEG:Tjpegimage;
    begin
    try
      if OpenPictureDialog1.Execute then
      begin
        if uppercase(ExtractFileExt(OpenPictureDialog1.FileName))='.BMP' then
        begin
          ImageBMP:=Tbitmap.Create;
          ImageJPEG:=TjpegImage.Create;
          ImageJPEG.LoadFromFile(bsSkinOpenPictureDialog1.FileName);
          ImageJPEG.Assign(ImageBMP);
          ImageJPEG.SaveToFile(ExtractFilePath(application.ExeName)+'TempBMP.JPEG');
          Image1.Picture.LoadFromFile(ExtractFilePath(application.ExeName)+'TempBMP.JPEG');
        end
        else
         Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
      end;
      except
     Message1.MessageDlg('您选择的图片格式有误,请从新选择!', mtInformation, [mbOK], 0);
      exit;
      end;
    end;**********************(  bmp to  jpeg )*****************************procedure Tfrm_Probation.bsSkinButton5Click(Sender: TObject);
    var
      ImageBMP:Tbitmap;
      ImageJPEG:Tjpegimage;
    begin
    try
      if OpenPictureDialog1.Execute then
      begin
        if uppercase(ExtractFileExt(OpenPictureDialog1.FileName))='.JPG' then
        begin
          ImageBMP:=Tbitmap.Create;
          ImageJPEG:=TjpegImage.Create;
          ImageJPEG.LoadFromFile(bsSkinOpenPictureDialog1.FileName);
          ImageBMP.Assign(ImageJPEG);
          ImageBMP.SaveToFile(ExtractFilePath(application.ExeName)+'TempBMP.BMP');
          Image1.Picture.LoadFromFile(ExtractFilePath(application.ExeName)+'TempBMP.BMP');
        end
        else
         Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
      end;
      except
     Message1.MessageDlg('您选择的图片格式有误,请从新选择!', mtInformation, [mbOK], 0);
      exit;
      end;
    end;
      

  4.   

    给你贴一段代码,绝对能用,
    Jpeg-file to bmp-file
    /////////////////////////////////////////////////
    Button1Click procedure creates variable of TJPEGImage type and loads a picture stored in a file.
    Button2Click procedure creates variable of TBitmap type and sets jpeg object to this variable. suses JPEG;
    ...
    var
     JPEGImage: TJPEGImage;
    ...
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      JPEGImage:=TJPEGImage.Create;
      if OpenDialog1.Execute then
      begin
        JPEGImage.LoadFromFile(OpenDialog1.FileName);
        Image1.Canvas.Draw(0,0,JPEGImage);
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      Bitmap: TBitmap;
    begin
      try
        Bitmap:=TBitmap.Create;
        with Bitmap do
        begin
          PixelFormat:=pf24bit;
          Height:=JPEGImage.Height;
          Width:=JPEGImage.Width;
          Canvas.Draw(0,0, JPEGImage);
        end;
        if SaveDialog1.Execute then
          Bitmap.SaveToFile(SaveDialog1.FileName);
        Label1.Caption:='Convertation finised';
      finally
        Bitmap.Free;
        JPEGImage.Free;
      end;
    end;
      

  5.   

    接着:BMP to JPG
    Button1Click procedure creates variable of TBitmap type and loads a picture stored in a file.
    Button2Click procedure creates variable of TJPEGImage type and assignes bitmap object to this variable. uses JPEG;
    ...
    var
      Bitmap: TBitmap;
    ...
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if OpenDialog1.Execute then
      begin
        Bitmap:=TBitmap.Create;
        Bitmap.LoadFromFile(OpenDialog1.FileName);
        Image1.Picture.LoadFromFile(OpenDialog1.FileName);
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      JPEGImage: TJPEGImage;
    begin
      try
        JPEGImage:=TJPEGImage.Create;
        JPEGImage.CompressionQuality:=80;
        JPEGImage.Assign(Bitmap);
        if SaveDialog1.Execute then
          JPEGImage.SaveToFile(SaveDialog1.FileName);
        Label1.Caption:='Convertation finished';
      finally
        Bitmap.Free;
        JPEGImage.Free;
      end;
    end;