344 lines
9.7 KiB
ObjectPascal
344 lines
9.7 KiB
ObjectPascal
unit umodify;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, ExtCtrls, StdCtrls, Spin;
|
||
|
||
type
|
||
TForm3 = class(TForm)
|
||
Label1: TLabel;
|
||
Label2: TLabel;
|
||
SpinEdit1: TSpinEdit;
|
||
SpinEdit2: TSpinEdit;
|
||
Button1: TButton;
|
||
Button2: TButton;
|
||
Button3: TButton;
|
||
Button4: TButton;
|
||
Bevel1: TBevel;
|
||
ScrollBox1: TScrollBox;
|
||
Label3: TLabel;
|
||
SpinEdit3: TSpinEdit;
|
||
OpenDialog1: TOpenDialog;
|
||
Button5: TButton;
|
||
Button6: TButton;
|
||
SaveDialog1: TSaveDialog;
|
||
Label4: TLabel;
|
||
Edit1: TEdit;
|
||
Image1: TImage;
|
||
procedure Button2Click(Sender: TObject);
|
||
procedure SpinEdit1Change(Sender: TObject);
|
||
procedure SpinEdit2Change(Sender: TObject);
|
||
procedure Button3Click(Sender: TObject);
|
||
procedure FormCreate(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure Button5Click(Sender: TObject);
|
||
procedure makegrid(w, h: integer);
|
||
procedure Button4Click(Sender: TObject);
|
||
procedure streamToBmp(Stream: TStream; const Width, Height,
|
||
ColorDepth, OffBits: Integer; Bmp: TBitmap);
|
||
procedure Button1Click(Sender: TObject);
|
||
procedure Button6Click(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
public
|
||
{ Public declarations }
|
||
id, dw, dh: integer;
|
||
mbmp: tbitmap;
|
||
uclear: boolean;
|
||
PRowCount, PColCount, cellwidth, cellheight: integer;
|
||
end;
|
||
|
||
var
|
||
Form3: TForm3;
|
||
|
||
implementation
|
||
|
||
uses umain;
|
||
|
||
{$R *.dfm}
|
||
|
||
procedure TForm3.Button2Click(Sender: TObject);
|
||
begin
|
||
CLOSE;
|
||
end;
|
||
|
||
procedure TForm3.SpinEdit1Change(Sender: TObject);
|
||
begin
|
||
if SpinEdit1.Value = 0 then
|
||
Image1.Visible := false else
|
||
begin
|
||
PColCount := SpinEdit1.Value;
|
||
mbmp.Width := SpinEdit1.Value;
|
||
if Form3.Showing then
|
||
makegrid(SpinEdit1.Value, SpinEdit2.Value);
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.SpinEdit2Change(Sender: TObject);
|
||
begin
|
||
if SpinEdit2.Value = 0 then
|
||
Image1.Visible := false else
|
||
begin
|
||
pRowCount := SpinEdit2.Value;
|
||
mbmp.Height := SpinEdit2.Value;
|
||
if Form3.Showing then
|
||
makegrid(SpinEdit1.Value, SpinEdit2.Value);
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.Button3Click(Sender: TObject);
|
||
var
|
||
ms: TMemoryStream;
|
||
FileHeader: TBitmapFileHeader;
|
||
InfoHeader: TBitmapInfoHeader;
|
||
tmpBmp: tbitmap;
|
||
begin
|
||
if OpenDialog1.Execute then
|
||
begin
|
||
uclear := true;
|
||
ms := TMemoryStream.Create;
|
||
tmpBmp := TBitmap.Create;
|
||
tmpBmp.PixelFormat := pf24bit;
|
||
tmpBmp.Canvas.Lock;
|
||
|
||
ms.LoadFromFile(OpenDialog1.FileName);
|
||
ms.Read(FileHeader, SizeOf(TBitmapFileHeader));
|
||
ms.Read(InfoHeader, SizeOf(TBitmapInfoHeader));
|
||
tmpBmp.Width := InfoHeader.biWidth;
|
||
tmpBmp.Height := InfoHeader.biheight;
|
||
tmpBmp.Canvas.Brush.Color := clBlack;
|
||
tmpBmp.Canvas.FillRect(Rect(0, 0, tmpBmp.Width, tmpBmp.Height));
|
||
streamToBmp(ms, tmpBmp.Width, tmpBmp.height, InfoHeader.biBitCount, FileHeader.bfOffBits, tmpBmp);
|
||
|
||
mbmp.Width := SpinEdit1.Value;
|
||
mbmp.Height := SpinEdit2.Value;
|
||
mbmp.Canvas.Lock;
|
||
mbmp.Canvas.Brush.Color := clBlack;
|
||
mbmp.Canvas.FillRect(Rect(0, 0, mbmp.Width, mbmp.Height));
|
||
mbmp.Canvas.StretchDraw(Rect(0, 0, mbmp.Width, mbmp.Height), tmpBmp);
|
||
mbmp.Canvas.Unlock;
|
||
tmpBmp.Canvas.Unlock;
|
||
FreeAndNil(tmpBmp);
|
||
FreeAndNil(ms);
|
||
makegrid(SpinEdit1.Value, SpinEdit2.Value);
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.FormCreate(Sender: TObject);
|
||
begin
|
||
mbmp := TBitmap.Create;
|
||
mbmp.PixelFormat := pf24bit;
|
||
uclear := false;
|
||
end;
|
||
|
||
procedure TForm3.FormShow(Sender: TObject);
|
||
begin
|
||
if Form1.editmode = 1 then
|
||
begin
|
||
makegrid(Form1.fontlist[SpinEdit3.Value].width,
|
||
Form1.fontlist[SpinEdit3.Value].height);
|
||
end else if Form1.editmode = 2 then
|
||
begin
|
||
makegrid(Form1.bitmaplist[SpinEdit3.Value].width,
|
||
Form1.bitmaplist[SpinEdit3.Value].height);
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.Button5Click(Sender: TObject);
|
||
begin
|
||
uclear := false;
|
||
SpinEdit1.Value := dw;
|
||
SpinEdit2.Value := dh;
|
||
makegrid(dw, dh);
|
||
end;
|
||
|
||
procedure TForm3.makegrid(w, h: integer);
|
||
var
|
||
i, j, x, y: integer;
|
||
p: PByteArray;
|
||
Frame: trect;
|
||
bmp: tbitmap;
|
||
r,g:byte;
|
||
begin
|
||
if uclear = false then
|
||
begin
|
||
mbmp.Width := w;
|
||
mbmp.height := h;
|
||
mbmp.Canvas.Brush.Color := clblack;
|
||
mbmp.Canvas.FillRect(rect(0, 0, mbmp.Width, mbmp.height));
|
||
if form1.editmode = 1 then
|
||
mbmp.Canvas.Draw(0, 0, Form1.fontlist[SpinEdit3.Value].bmplist) else
|
||
if form1.editmode = 2 then
|
||
mbmp.Canvas.Draw(0, 0, Form1.bitmaplist[SpinEdit3.Value].bmplist);
|
||
end;
|
||
Image1.Visible := true;
|
||
//<2F><><EFBFBD><EFBFBD>paintbox <20>ֿ<EFBFBD><D6BF><EFBFBD>ʾ
|
||
Image1.Width := w * form1.pixelsrule + 1;
|
||
Image1.height := h * form1.pixelsrule + 1;
|
||
|
||
bmp := TBitmap.Create;
|
||
bmp.PixelFormat := pf24bit;
|
||
bmp.Width := Image1.Width;
|
||
bmp.height := Image1.height;
|
||
bmp.Canvas.Brush.Color := rgb(64, 64, 64);
|
||
bmp.Canvas.FillRect(Rect(0, 0, bmp.Width, bmp.height));
|
||
PColCount := w;
|
||
PRowCount := h;
|
||
|
||
// Calculate grid cell size
|
||
CellWidth := form1.pixelsrule;
|
||
CellHeight := form1.pixelsrule;
|
||
|
||
y := 0;
|
||
for i := 0 to mbmp.height - 1 do
|
||
begin
|
||
p := mbmp.ScanLine[i];
|
||
x := 0;
|
||
for j := 0 to mbmp.Width - 1 do
|
||
begin
|
||
Frame.Left := x;
|
||
Frame.Right := x + CellWidth;
|
||
Frame.Top := y;
|
||
Frame.Bottom := y + CellHeight;
|
||
DrawEdge(bmp.Canvas.Handle, Frame, BDR_SUNKENINNER, BF_ADJUST or BF_LEFT);
|
||
DrawEdge(bmp.Canvas.Handle, Frame, BDR_SUNKENINNER, BF_ADJUST or BF_top);
|
||
if p[j * 3 + 2]>=128 then
|
||
r:=255 else r:=0;
|
||
if p[j * 3 + 1]>=128 then
|
||
g:=255 else g:=0;
|
||
bmp.Canvas.Brush.Color := rgb(r, g, 0);
|
||
bmp.Canvas.FillRect(Frame);
|
||
inc(x, CellWidth);
|
||
end;
|
||
inc(y, CellHeight);
|
||
end;
|
||
Image1.Picture.Bitmap := bmp;
|
||
bmp.Free;
|
||
end;
|
||
|
||
procedure TForm3.Button4Click(Sender: TObject);
|
||
begin
|
||
uclear := true;
|
||
mbmp.Width := SpinEdit1.Value;
|
||
mbmp.height := SpinEdit2.Value;
|
||
mbmp.Canvas.Brush.Color := clblack;
|
||
mbmp.Canvas.FillRect(rect(0, 0, mbmp.Width, mbmp.height));
|
||
makegrid(SpinEdit1.Value, SpinEdit2.Value);
|
||
end;
|
||
|
||
procedure TForm3.streamToBmp(Stream: TStream; const Width, Height,
|
||
ColorDepth, OffBits: Integer; Bmp: TBitmap);
|
||
var
|
||
RemLen, DataLen, i: Integer;
|
||
begin
|
||
case ColorDepth of
|
||
1:
|
||
begin
|
||
Bmp.PixelFormat := pf1Bit;
|
||
DataLen := (Width + 7) shr 3;
|
||
end;
|
||
4:
|
||
begin
|
||
Bmp.PixelFormat := pf4Bit;
|
||
DataLen := (Width + 1) shr 1;
|
||
end;
|
||
8:
|
||
begin
|
||
Bmp.PixelFormat := pf8Bit;
|
||
DataLen := Width;
|
||
end;
|
||
15:
|
||
begin
|
||
Bmp.PixelFormat := pf15Bit;
|
||
DataLen := Width shl 1;
|
||
end;
|
||
16:
|
||
begin
|
||
Bmp.PixelFormat := pf16Bit;
|
||
DataLen := Width shl 1;
|
||
end;
|
||
24:
|
||
begin
|
||
Bmp.PixelFormat := pf24Bit;
|
||
DataLen := Width shl 1 + Width;
|
||
end;
|
||
32:
|
||
begin
|
||
Bmp.PixelFormat := pf32Bit;
|
||
DataLen := Width shl 2;
|
||
end;
|
||
end;
|
||
Bmp.Width := Width;
|
||
Bmp.Height := Height;
|
||
RemLen := (DataLen + 3) shr 2 shl 2; //- DataLen;
|
||
for i := 0 to Height - 1 do
|
||
begin
|
||
Stream.Position := OffBits + RemLen * (Height - 1 - i);
|
||
Stream.Read(Bmp.ScanLine[i]^, DataLen);
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.Button1Click(Sender: TObject);
|
||
begin
|
||
if Form1.editmode = 1 then
|
||
begin
|
||
if MessageBox(Application.Handle, 'Do You Want to Modify Selected Font?', 'Modify Hint', MB_OKCANCEL + MB_ICONINFORMATION) = MrOK then
|
||
begin
|
||
Form1.AdvStringGrid2.Cells[2, id + 1] := inttostr(id);
|
||
Form1.AdvStringGrid2.Cells[3, id + 1] := inttostr(SpinEdit1.Value);
|
||
Form1.AdvStringGrid2.Cells[4, id + 1] := inttostr(SpinEdit2.Value);
|
||
|
||
Form1.fontlist[id].width := SpinEdit1.Value;
|
||
Form1.fontlist[id].height := SpinEdit2.Value;
|
||
if Form1.fontlist[id].bmplist <> nil then
|
||
Form1.fontlist[id].bmplist.Free;
|
||
|
||
Form1.fontlist[id].bmplist := TBitmap.Create;
|
||
Form1.fontlist[id].bmplist.PixelFormat := pf24bit;
|
||
Form1.fontlist[id].bmplist.Width := SpinEdit1.Value;
|
||
Form1.fontlist[id].bmplist.height := SpinEdit2.Value;
|
||
Form1.fontlist[id].bmplist.Canvas.Brush.Color := clBlack;
|
||
Form1.fontlist[id].bmplist.Canvas.FillRect(Rect(0, 0, SpinEdit1.Value, SpinEdit2.Value));
|
||
Form1.fontlist[id].bmplist.Canvas.Draw(0, 0, mbmp);
|
||
|
||
Form1.AdvStringGrid2Click(sender);
|
||
close;
|
||
end;
|
||
end else if Form1.editmode = 2 then
|
||
begin
|
||
if MessageBox(Application.Handle, 'Do You Want to Modify Selected Bitmwp?', 'Modify Hint', MB_OKCANCEL + MB_ICONINFORMATION) = MrOK then
|
||
begin
|
||
Form1.AdvStringGrid2.Cells[2, id + 1] := edit1.Text;
|
||
Form1.AdvStringGrid2.Cells[3, id + 1] := inttostr(SpinEdit1.Value);
|
||
Form1.AdvStringGrid2.Cells[4, id + 1] := inttostr(SpinEdit2.Value);
|
||
|
||
Form1.bitmaplist[id].width := SpinEdit1.Value;
|
||
Form1.bitmaplist[id].height := SpinEdit2.Value;
|
||
if Form1.bitmaplist[id].bmplist <> nil then
|
||
Form1.bitmaplist[id].bmplist.Free;
|
||
|
||
Form1.bitmaplist[id].bmplist := TBitmap.Create;
|
||
Form1.bitmaplist[id].bmplist.PixelFormat := pf24bit;
|
||
Form1.bitmaplist[id].bmplist.Width := SpinEdit1.Value;
|
||
Form1.bitmaplist[id].bmplist.height := SpinEdit2.Value;
|
||
Form1.bitmaplist[id].bmplist.Canvas.Brush.Color := clBlack;
|
||
Form1.bitmaplist[id].bmplist.Canvas.FillRect(Rect(0, 0, SpinEdit1.Value, SpinEdit2.Value));
|
||
Form1.bitmaplist[id].bmplist.Canvas.Draw(0, 0, mbmp);
|
||
|
||
Form1.AdvStringGrid2Click(sender);
|
||
close;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TForm3.Button6Click(Sender: TObject);
|
||
begin
|
||
if SaveDialog1.Execute then
|
||
mbmp.SaveToFile(SaveDialog1.FileName);
|
||
end;
|
||
|
||
end.
|
||
|