| 1 | unit FormMain;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | { TFormMain }
|
|---|
| 11 |
|
|---|
| 12 | TFormMain = class(TForm)
|
|---|
| 13 | MemoLog: TMemo;
|
|---|
| 14 | procedure FormShow(Sender: TObject);
|
|---|
| 15 | private
|
|---|
| 16 |
|
|---|
| 17 | public
|
|---|
| 18 | procedure ProcessImage(InputFileName, OutputFileName: string);
|
|---|
| 19 | end;
|
|---|
| 20 |
|
|---|
| 21 | var
|
|---|
| 22 | FormMain: TFormMain;
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | implementation
|
|---|
| 26 |
|
|---|
| 27 | {$R *.lfm}
|
|---|
| 28 |
|
|---|
| 29 | { TFormMain }
|
|---|
| 30 |
|
|---|
| 31 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 32 | begin
|
|---|
| 33 | MemoLog.Lines.Clear;
|
|---|
| 34 | ProcessImage('Input.png', 'Output.zip');
|
|---|
| 35 | MemoLog.Lines.Add('Finished');
|
|---|
| 36 | end;
|
|---|
| 37 |
|
|---|
| 38 | procedure TFormMain.ProcessImage(InputFileName, OutputFileName: string);
|
|---|
| 39 | var
|
|---|
| 40 | Image: TImage;
|
|---|
| 41 | F: TFileStream;
|
|---|
| 42 | Buffer: array of Byte;
|
|---|
| 43 | Offset: TPoint;
|
|---|
| 44 | X, Y: Integer;
|
|---|
| 45 | Pixel: Cardinal;
|
|---|
| 46 | Line: PColor;
|
|---|
| 47 | I: Integer;
|
|---|
| 48 | S: Integer;
|
|---|
| 49 | begin
|
|---|
| 50 | Image := TImage.Create(nil);
|
|---|
| 51 | Image.Picture.LoadFromFile(InputFileName);
|
|---|
| 52 | Offset := Point(0, 100);
|
|---|
| 53 |
|
|---|
| 54 | F := TFileStream.Create(OutputFileName, fmOpenWrite or fmCreate);
|
|---|
| 55 | SetLength(Buffer, Image.Picture.Bitmap.Width * Image.Picture.Bitmap.Height * 4);
|
|---|
| 56 | X := Offset.X;
|
|---|
| 57 | Y := Offset.Y;
|
|---|
| 58 | I := 0;
|
|---|
| 59 | Line := Image.Picture.Bitmap.ScanLine[Y];
|
|---|
| 60 | Pixel := PColor(Line + X)^ and $ffffff;
|
|---|
| 61 | Inc(Y);
|
|---|
| 62 | S := ((Pixel shr 16) and $ff) or (Pixel and $ff00) or (((Pixel shr 0) and $ff) shl 16);
|
|---|
| 63 | SetLength(Buffer, S);
|
|---|
| 64 | Inc(Y);
|
|---|
| 65 | while Y < Image.Picture.Bitmap.Height do begin
|
|---|
| 66 | Line := Image.Picture.Bitmap.ScanLine[Y];
|
|---|
| 67 | X := Offset.X;
|
|---|
| 68 | while X < Image.Picture.Bitmap.Width do begin
|
|---|
| 69 | Pixel := PColor(Line + X)^;
|
|---|
| 70 | Buffer[I] := (((Pixel shr 20) and $f) shl 0) or
|
|---|
| 71 | (((Pixel shr 12) and $f) shl 4);
|
|---|
| 72 | Inc(X, 2);
|
|---|
| 73 | Inc(I, 1);
|
|---|
| 74 | if I >= Length(Buffer) then Break;
|
|---|
| 75 | end;
|
|---|
| 76 | if I >= Length(Buffer) then Break;
|
|---|
| 77 | Inc(Y, 2);
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | F.Write(Buffer[0], Length(Buffer));
|
|---|
| 81 | F.Size := Length(Buffer);
|
|---|
| 82 | F.Free;
|
|---|
| 83 | Image.Free;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | end.
|
|---|
| 87 |
|
|---|