📄 imagewin.pas
字号:
unit ImageWin;
{
BMP2ASM.EXE - 9/99, John Gerthoffer, American Auto-Matrix
This program takes a BMP file and scans it into 8-bit high rows.
Each row is converted into a text file format for inclusion into
assembly language programs.
The intended target is the PIC microprocessor.
Written to support the Smart Stat project.
}
interface
uses Windows, Classes, Graphics, Forms, Controls,
FileCtrl, StdCtrls, ExtCtrls, Buttons, Spin, ComCtrls,
clipbrd;
type
TImageForm = class(TForm)
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
FileEdit: TEdit;
Panel1: TPanel;
Image1: TImage;
FileListBox1: TFileListBox;
Bevel1: TBevel;
FilterComboBox1: TFilterComboBox;
StretchCheck: TCheckBox;
Panel2: TPanel;
Image2: TImage;
ConvertBtn: TButton;
Label2: TLabel;
AutoConvertBox: TCheckBox;
ASMEdit: TEdit;
Memo1: TMemo;
Label3: TLabel;
procedure FileListBox1Click(Sender: TObject);
procedure StretchCheckClick(Sender: TObject);
procedure FileEditKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure ConvertBtnClick(Sender: TObject);
procedure Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure AutoConvertBoxClick(Sender: TObject);
private
FormCaption: string;
MouseX, MouseY: Integer;
procedure ConvertBMP2ASM;
end;
var
ImageForm: TImageForm;
implementation
uses ViewWin, SysUtils;
{$R *.DFM}
procedure TImageForm.FileListBox1Click(Sender: TObject);
var
FileExt: string[4];
begin
FileExt := AnsiUpperCase(ExtractFileExt(FileListBox1.Filename));
if (FileExt = '.BMP') or (FileExt = '.ICO') or (FileExt = '.WMF') or
(FileExt = '.EMF') then
begin
Image1.Picture.LoadFromFile(FileListBox1.Filename);
Caption := FormCaption + ExtractFilename(FileListBox1.Filename);
if (FileExt = '.BMP') then
begin
Caption := Caption +
Format(' (%d x %d)', [Image1.Picture.Width, Image1.Picture.Height]);
Image2.Width := (Image1.Picture.Width * 4);
Image2.Height := (Image1.Picture.Height * 4);
Image2.Picture := Image1.Picture;
end
else
if FileExt = '.ICO' then Icon := Image1.Picture.Icon;
if (FileExt = '.WMF') or (FileExt = '.EMF') then
ViewForm.Image1.Picture.Metafile := Image1.Picture.Metafile;
if AutoConvertBox.Checked then
ConvertBMP2ASM;
end;
end;
procedure TImageForm.StretchCheckClick(Sender: TObject);
begin
Image1.Stretch := StretchCheck.Checked;
end;
procedure TImageForm.FileEditKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
FileListBox1.ApplyFilePath(FileEdit.Text);
Key := #0;
end;
end;
procedure TImageForm.FormCreate(Sender: TObject);
begin
FormCaption := Caption + ' - ';
end;
procedure TImageForm.ConvertBtnClick(Sender: TObject);
begin
ConvertBMP2ASM;
end;
procedure TImageForm.ConvertBMP2ASM;
var
c :Longint;
x, y, NumScanLines, MaxX, MaxY, i, j, yTemp :Integer;
line : integer;
OutFileName :string;
ASMEdit :string;
F :TextFile;
S :array[0..80] of char;
begin
MaxX := Image1.Picture.Width;
MaxY := Image1.Picture.Height;
NumScanLines := MaxY div 8;
if (MaxY mod 8) > 0 then
NumScanLines := NumScanLines + 1;
OutFileName := ExtractFilename(FileListBox1.Filename);
x := Length(OutFileName) - sizeof('.BMP');
StrLCopy(S, PChar(OutFileName), x);
OutFileName := string(S) + '.ASM';
AssignFile(F, OutFileName);
Rewrite(F);
//Create file reference line. Ex. ";D:\Stat\Graphics\Bmp\0.BMP"
Memo1.Lines.Clear();
ASMEdit := ';'+ FileListBox1.Filename;
ASMEdit := ASMEdit + Format(' (%d x %d)',
[Image1.Picture.Width, Image1.Picture.Height]);
Writeln(F, ASMEdit);
Memo1.Lines.Add(ASMEdit);
ASMEdit := '';
for line:=0 to (NumScanLines-1) do
begin
ASMEdit := chr(9) + 'dt ' + chr(9);
for x:= 0 to (MaxX - 1) do
begin
i := 0;
y := 7; //y is the bit counter. Start with MSB
while y >= 0 do
begin
yTemp := (line*8)+y;
// Convert BMP colors to Black & White
// c= 0x00000000 for Black, c= 0x00FFFFFF for White.
// c = 0xFFFFFFFF for not defined, not used, blank, whatever.
c := Image1.Canvas.Pixels[x, yTemp]; // Get color from BMP
j := 0; // Set bit color = white for default
if (c < clGray) then // Anything darker than gray is now black
j := 1;
if (c = $FFFFFFFF) then // Not used bits are white
j := 0;
i := i + j; // Add bit value to our column bitmap
if y > 0 then // Shift color bit left (unless bit 0)
i := i shl 1;
y := y -1; //dec bit counter
end;
// Convert column to hex for data table
ASMEdit := ASMEdit + '0x' + IntToHex(i,2);
// Add concatinator (except for last byte)
if x < (MaxX-1) then
ASMEdit := ASMEdit + ',';
end;
Writeln(F, ASMEdit);
Memo1.Lines.Add(ASMEdit);
end;
Writeln(F, ''); //add CR, LF
CloseFile(F);
end;
procedure TImageForm.Image2MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
MouseX := X;
MouseY := Y;
Label2.caption := IntToStr(X div 4) + ',' + IntToStr(Y div 4);
end;
procedure TImageForm.AutoConvertBoxClick(Sender: TObject);
begin
if AutoConvertBox.Checked then
ConvertBMP2ASM;
end;
End.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -