Показать сообщение отдельно
  #5  
Старый 25.06.2009, 13:30
Rat Rat вне форума
Активный
 
Регистрация: 12.09.2008
Сообщения: 391
Репутация: 6078
По умолчанию

Делаю так:

Код:
unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Jpeg, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Image1: TImage;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    procedure FadeOut(const BMP: TImage; Pause: integer);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  jpeg:  TJPEGImage;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    jpeg.LoadFromFile(OpenDialog1.FileName);
    Image1.Picture.Assign(jpeg);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  jpeg := TJPEGImage.Create;
  jpeg.CompressionQuality := 100;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FadeOut(Image1, 10);
end;

procedure TForm1.FadeOut(const BMP:TImage; Pause:integer) ;
var
  BytesPorScan : integer;
  w,h : integer;
  p : pByteArray;
  counter : integer;

begin
  {This only works with 24 or 32 bits bitmaps}
  If Not (BMP.Picture.Bitmap.PixelFormat in [pf24Bit, pf32Bit])
  then raise exception.create ('Error, bitmap format not supported.') ;

      try
       BytesPorScan:=
        Abs(Integer(BMP.Picture.Bitmap.ScanLine[1])-
            Integer(BMP.Picture.Bitmap.ScanLine[0])) ;
      except
        raise exception.create('Error') ;
      end;

      {Decrease the RGB for each single pixel}
      for counter:=1 to 256 do
      begin
        for h:=0 to BMP.Picture.Bitmap.Height-1 do
        begin
          P:=BMP.Picture.Bitmap.ScanLine[h];
          for w:=0 to BytesPorScan-1 do
            if P^[w] >0 then P^[w]:=P^[w]-1;
        end;
        Sleep(Pause) ;
      BMP.Refresh;
      end;
    end; {procedure FadeOut}

end.

В TImage1 загружается jpg. Вроде как конвертируется в bmp. При нажатии на button2 выдается ошибка "Error, bitmap format not supported."

Если я коментирую строки:
Код:
  If Not (BMP.Picture.Bitmap.PixelFormat in [pf24Bit, pf32Bit])
  then raise exception.create ('Error, bitmap format not supported.') ;

То далее выдается ошибка: 'Scan line index out of range'.

Что не так?