📄 bmpfuns.pas
字号:
unit BmpFuns;
interface
uses
SysUtils,Controls,Graphics,ExtCtrls,Types;
procedure ShowAllSizeOfImage(Image:TBitmap);
// procedure ShowBmpPicture(Image:TImage; var Bmp:TBitMap);
procedure FreeFontInSide(var bmp:TBitMap);
procedure LineFontOutSide(var bmp:TBitMap);
procedure View3dFont(var bmp:TBitMap);
implementation
uses ShowImgU;
procedure ShowAllSizeOfImage(Image:TBitMap);
var
ph,pw,ih,iw:Integer;
begin
ShowImgF:=TShowImgF.Create(Nil);
pw:=Image.Width;
ph:=Image.Height;
With ShowImgF do begin
Image1.Picture.Bitmap.Assign(Image); // Assign(Image.Picture);
try
Caption:='查看编辑的文字,图象宽x高:'+IntToStr(pw)+'x'+IntToStr(ph);
ih:=Panel3.Height;
iw:=Panel3.Width;
ph:=Image1.Picture.Height;
pw:=Image1.Picture.Width;
if (ph>ih) and (pw>iw) then begin
Panel3.Height:=Image1.Picture.Height;
Panel3.Width:=Image1.Picture.Width;
Label1.Cursor:=crSizeAll;
end else if (ph>ih) then begin
Panel3.Height:=Image1.Picture.Height;
Image1.Left:=Trunc((Panel3.Width-Image1.Picture.Width)/2);
Label1.Cursor:=crSizeNS;
end else if (pw>iw) then begin
Panel3.Width:=Image1.Picture.Width;
Image1.Top:=Trunc((Panel3.Height-Image1.Picture.Height)/2);
Label1.Cursor:=crSizeWE;
end else begin
Image1.Left:=Trunc((Panel3.Width-Image1.Picture.Width)/2);
Image1.Top:=Trunc((Panel3.Height-Image1.Picture.Height)/2);
end;
ShowModal;
finally
Free;
end;
end;
end;
{
procedure ShowBmpPicture(Image:TImage; var Bmp:TBitMap);
var
ph,pw,ih,iw:Integer;
//oiw,oih:Integer;
begin
Image.Align:=alClient;
Image.Stretch:=False;
Image.Picture.Bitmap.Assign(Bmp);
ph:=Image.Picture.Bitmap.Height;
pw:=Image.Picture.Bitmap.Width;
ih:=Image.Height;
iw:=Image.Width;
Image.Align:=alNone;
if (ph>ih) or (pw>iw) then begin
//oih:=Image.Height;
//oiw:=Image.Width;
if iw/ih>pw/ph then begin
//Image.Width:=Trunc(pw*ih/ph);
//Image.Left:=(oiw-Image.Width) div 2;
//oih:=Image.Height;
Image.Left:=0;
//Image.Top:=(oih-Image.Height) div 2;
end else begin
//Image.Height:=Trunc(iw*ph/pw);
//Image.Top:=(oih-Image.Height) div 2;
//oiw:=Image.Width;
Image.Top:=0;
//Image.Left:=(oiw-Image.Width) div 2;
end;
//Image.Stretch:=True;
end;
Image.AutoSize:=True;
//Image.Refresh;
end; }
procedure FreeFontInSide(var bmp:TBitMap);
var
c0,c:TColor;
images:TBitMap;
i,j:Integer;
wleft,wright:Integer;
wtop,wbottom:Integer;
begin
Images:=TBitMap.Create; //原始点颜色 // c0 := Img_Select.canvas.Pixels[0, 0];
Images.Width:=bmp.Width;
Images.Height:=bmp.Height;
// images.canvas.brush.color := c0;
images.canvas.brush.color := clBlack;
images.canvas.fillrect(Rect(0, 0, images.width, images.height));
wleft:=0;
wright:=Images.Width;
wtop:=0;
wbottom:=Images.Height;
c0:=clBlack;
for i := wleft to wright - 1 do
for j := wtop to wbottom - 1 do
if (bmp.canvas.pixels[i, j] <> c0) then begin
c := bmp.canvas.pixels[i, j]; //当前点颜色
//左上角 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i - 1, j - 1] <> c0) then images.canvas.pixels[i - 1, j - 1] := c0
else images.canvas.pixels[i - 1, j - 1] := c;
//正上方 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i, j - 1] <> c0) then images.canvas.pixels[i, j - 1] := c0
else images.canvas.pixels[i, j - 1] := c;
//右上方 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i + 1, j - 1] <> c0) then images.canvas.pixels[i + 1, j - 1] := c0
else images.canvas.pixels[i + 1, j - 1] := c;
//左下角 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i - 1, j + 1] <> c0) then images.canvas.pixels[i - 1, j + 1] := c0
else images.canvas.pixels[i - 1, j + 1] := c;
//正下方 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i, j + 1] <> c0) then images.canvas.pixels[i, j + 1] := c0
else images.canvas.pixels[i, j + 1] := c;
//右下角 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i + 1, j + 1] <> c0) then images.canvas.pixels[i + 1, j + 1] := c0
else images.canvas.pixels[i + 1, j + 1] := c;
//左中 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i - 1, j] <> c0) then images.canvas.pixels[i - 1, j] := c0
else images.canvas.pixels[i - 1, j] := c;
//右中 和原始点不一样,颜色取反
if (bmp.canvas.pixels[i + 1, j] <> c0) then images.canvas.pixels[i + 1, j] := c0
else images.canvas.pixels[i + 1, j] := c;
end;
try
bmp.Canvas.Draw(0,0,Images);
finally
images.Free
end;
end;
procedure LineFontOutSide(var bmp:TBitMap);
var
c0,c:TColor;
images:TBitMap;
i,j:Integer;
wleft,wright:Integer;
wtop,wbottom:Integer;
begin
Images:=TBitMap.Create; //原始点颜色 // c0 := Img_Select.canvas.Pixels[0, 0];
Images.Width:=Bmp.Width;
Images.Height:=Bmp.Height;
// images.canvas.brush.color := c0;
images.canvas.brush.color := clBlack;
images.canvas.fillrect(rect(0, 0, images.width, images.height));
wleft:=0;
wright:=Images.Width;
wtop:=0;
wbottom:=Images.Height;
c0:=clBlack;
for i := wleft to wright - 1 do
for j := wtop to wbottom - 1 do
if (Bmp.canvas.pixels[i, j] <> c0) then begin
c := Bmp.canvas.pixels[i, j]; //当前点颜色
if (Bmp.canvas.pixels[i - 1, j - 1] <> c0) then //左上角 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i - 1, j - 1] := cllime;
clLime: images.canvas.pixels[i - 1, j - 1] := clred;
clYellow:images.canvas.pixels[i - 1, j - 1] := clred;
end
else images.canvas.pixels[i - 1, j - 1] := c;
if (Bmp.canvas.pixels[i, j - 1] <> c0) then //正上方 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i, j - 1] := clLime;
cllime: images.canvas.pixels[i, j - 1] := clred;
clYellow: images.canvas.pixels[i, j - 1] := clred;
end
else images.canvas.pixels[i, j - 1] := c;
if (Bmp.canvas.pixels[i + 1, j - 1] <> c0) then //右上方 和原始点不一样,颜色取反
case c of
clred:images.canvas.pixels[i + 1, j - 1] := cllime;
cllime:images.canvas.pixels[i + 1, j - 1] := clred;
clYellow: images.canvas.pixels[i + 1, j - 1] := clred;
end
else images.canvas.pixels[i + 1, j - 1] := c;
if (Bmp.canvas.pixels[i - 1, j + 1] <> c0) then //左下角 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i - 1, j + 1] := cllime;
cllime: images.canvas.pixels[i - 1, j + 1] := clred;
clyellow: images.canvas.pixels[i - 1, j + 1] := clred;
end
else images.canvas.pixels[i - 1, j + 1] := c;
if (Bmp.canvas.pixels[i, j + 1] <> c0) then //正下方 和原始点不一样,颜色取反
case c of
clred:images.canvas.pixels[i, j + 1] := cllime;
cllime: images.canvas.pixels[i, j + 1] := clred;
clyellow: images.canvas.pixels[i, j + 1] := clred;
end
else images.canvas.pixels[i, j + 1] := c;
//右下角 和原始点不一样,颜色取反
if (Bmp.canvas.pixels[i + 1, j + 1] <> c0) then
case c of
clred:images.canvas.pixels[i + 1, j + 1] := cllime;
cllime: images.canvas.pixels[i + 1, j + 1] := clred;
clyellow: images.canvas.pixels[i + 1, j + 1] := clred;
end
else images.canvas.pixels[i + 1, j + 1] := c;
//左中 和原始点不一样,颜色取反
if (Bmp.canvas.pixels[i - 1, j] <> c0) then
case c of
clred: images.canvas.pixels[i - 1, j] := cllime;
cllime: images.canvas.pixels[i - 1, j] := clred;
clyellow: images.canvas.pixels[i - 1, j] := clred;
end
else images.canvas.pixels[i - 1, j] := c;
//右中 和原始点不一样,颜色取反
if (Bmp.canvas.pixels[i + 1, j] <> c0) then
case c of
clred: images.canvas.pixels[i + 1, j] := cllime;
cllime: images.canvas.pixels[i + 1, j] := clred;
clyellow: images.canvas.pixels[i + 1, j] := clred;
end
else images.canvas.pixels[i + 1, j] := c;
end;
try
bmp.Canvas.Draw(0,0,Images);
finally
images.Free
end;
end;
procedure View3dFont(var bmp:TBitMap);
var
c0,c:TColor;
images:TBitMap;
i,j:Integer;
wleft,wright:Integer;
wtop,wbottom:Integer;
begin
Images:=TBitMap.Create; //原始点颜色// c0 := Bmp.canvas.Pixels[0, 0];
Images.Width:=bmp.Width;
Images.Height:=bmp.Height;
// images.canvas.brush.color := c0;
images.canvas.brush.color := clBlack;
images.canvas.fillrect(rect(0, 0, images.width, images.height));
wleft:=0;
wright:=Images.Width;
wtop:=0;
wbottom:=Images.Height;
c0:=clBlack;
for i := wleft to wright - 1 do
for j := wtop to wbottom - 1 do
if (Bmp.canvas.pixels[i, j] <> c0) then begin
c := Bmp.canvas.pixels[i, j]; //当前点颜色
{if (Bmp.canvas.pixels[i - 1, j - 1] <> c0) then //左上角 和原始点不一样,颜色取反
case c of
clLime: images.canvas.pixels[i - 1, j - 1] := clred;
clred: images.canvas.pixels[i - 1, j - 1] := cllime;
end
else images.canvas.pixels[i - 1, j - 1] := c; }
if (Bmp.canvas.pixels[i, j - 1] <> c0) then //正上方 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i, j - 1] := clLime;
cllime: images.canvas.pixels[i, j - 1] := clred;
clyellow: images.canvas.pixels[i, j - 1] := clred;
end
else images.canvas.pixels[i, j - 1] := c;
if (Bmp.canvas.pixels[i + 1, j - 1] <> c0) then //右上方 和原始点不一样,颜色取反
case c of
clred:images.canvas.pixels[i + 1, j - 1] := cllime;
cllime:images.canvas.pixels[i + 1, j - 1] := clred;
clyellow: images.canvas.pixels[i + 1, j - 1] := clred;
end
else images.canvas.pixels[i + 1, j - 1] := c;
{if (Bmp.canvas.pixels[i - 1, j + 1] <> c0) then //左下角 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i - 1, j + 1] := cllime;
cllime: images.canvas.pixels[i - 1, j + 1] := clred;
end
else images.canvas.pixels[i - 1, j + 1] := c; }
{if (Bmp.canvas.pixels[i, j + 1] <> c0) then //正下方 和原始点不一样,颜色取反
case c of
clred:images.canvas.pixels[i, j + 1] := cllime;
cllime: images.canvas.pixels[i, j + 1] := clred;
end
else images.canvas.pixels[i, j + 1] := c; }
{if (Bmp.canvas.pixels[i + 1, j + 1] <> c0) then //右下角 和原始点不一样,颜色取反
case c of
clred:images.canvas.pixels[i + 1, j + 1] := cllime;
cllime: images.canvas.pixels[i + 1, j + 1] := clred;
end
else images.canvas.pixels[i + 1, j + 1] := c; }
{if (Bmp.canvas.pixels[i - 1, j] <> c0) then //左中 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i - 1, j] := cllime;
cllime: images.canvas.pixels[i - 1, j] := clred;
end
else images.canvas.pixels[i - 1, j] := c; }
if (Bmp.canvas.pixels[i + 1, j] <> c0) then //右中 和原始点不一样,颜色取反
case c of
clred: images.canvas.pixels[i + 1, j] := cllime;
cllime: images.canvas.pixels[i + 1, j] := clred;
clyellow: images.canvas.pixels[i + 1, j] := clred;
end
else images.canvas.pixels[i + 1, j] := c;
end;
try
bmp.Canvas.Draw(0,0,Images);
finally
images.Free
end;
end;
procedure ChangBitmapBackColor(bkcolor:TColor; var bmp:TBitMap);
var
i,j:Integer;
sc:TColor;
images:TBitMap;
begin
Images:=TBitMap.Create; //原始点颜色// c0 := Bmp.canvas.Pixels[0, 0];
Images.Width:=bmp.Width;
Images.Height:=bmp.Height;
// images.canvas.brush.color := c0;
images.canvas.brush.color := clBlack;
images.canvas.fillrect(rect(0, 0, images.width, images.height));
for i:=0 to bmp.Width-1 do begin
for j:=0 to bmp.Height-1 do begin
sc:=bmp.Canvas.Pixels[i,j];
case bkcolor of
clred: begin
case sc of
clred: Images.Canvas.Pixels[i,j]:=clLime;
cllime: Images.Canvas.Pixels[i,j]:=clyellow;
clyellow:Images.Canvas.Pixels[i,j]:=clblack;
else Images.Canvas.Pixels[i,j]:=clred;
end;
end;
cllime: begin
case sc of
cllime: Images.Canvas.Pixels[i,j]:=clred;
clred: Images.Canvas.Pixels[i,j]:=clyellow;
clyellow:Images.Canvas.Pixels[i,j]:=clblack;
else Images.Canvas.Pixels[i,j]:=cllime;
end;
end;
clYellow:begin
case sc of
clyellow:Images.Canvas.Pixels[i,j]:=clblack;
cllime: Images.Canvas.Pixels[i,j]:=cllime;
clred: Images.Canvas.Pixels[i,j]:=clred;
else Images.Canvas.Pixels[i,j]:=clyellow;
end;
end;
clBlack: begin
case sc of
clblack: Images.Canvas.Pixels[i,j]:=clred;
else Images.Canvas.Pixels[i,j]:=clBlack;
end;
end;
end;
end;
end;
try
bmp.Canvas.Draw(0,0,images);
finally
images.Free
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -