📄 tmsuxlspictures.pas
字号:
end;
//There is no direct support for PNG, because there is not a standard Delphi class to support it.
//No direct support for wmf/emf, because it uses zlib and it would have to be added to the package list.
//To support it define USEPNGLIB at the top of this file
{$IFDEF USEPNGLIB}
xli_png:
begin
Png:=TPNGImage.Create;
try
Picture.Graphic:=Png;
finally
FreeAndNil(Png); //Remember TPicture.Graphic keeps a COPY of the TGraphic
end;
Picture.Graphic.LoadFromStream(Pic);
end;
{$IFDEF FLX_SUPPORTSWMF}
xli_wmf, xli_emf:
begin
Wmf:=TMetaFile.Create;
try
Picture.Graphic:=Wmf;
finally
FreeAndNil(Wmf);
end; //finally
LoadWmf(Picture, Pic, PicType);
end;
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$IFDEF FLX_CLX}
//Here png is directly supported. Not metafiles...
xli_Bmp, xli_Jpeg, xli_Png:
begin
Bmp:=TBitmap.Create;
try
Picture.Graphic:=Bmp;
finally
FreeAndNil(Bmp); //Remember TPicture.Graphic keeps a COPY of the TGraphic
end;
Picture.Graphic.LoadFromStream(Pic);
end;
{$ENDIF}
else Handled:=False;
end; //case
end;
procedure SaveImgStreamToDiskImage(const Pic: TStream; const PicType: TXlsImgTypes; const OutStream: TStream; out Saved: boolean);
begin
Saved := true;
case PicType of
xli_Emf,
xli_Wmf:
LoadWmfInStream(OutStream, Pic, PicType, Saved);
xli_Jpeg,
xli_Png,
xli_Bmp: OutStream.CopyFrom(Pic, Pic.Size);
else Saved := false;
end;
end;
{$IFDEF FLX_CLX}
{$IFDEF VER140}
Kylix3 is 140 too... and it allows patterns. Patterns are not allowed for d6/bcb6 clx.
{$DEFINE FLX_NOPATTERN}
{$ENDIF}
{$ENDIF}
procedure Fill8x8Image(const Bmp: TBitmap);
begin
Bmp.Canvas.Draw(0,4,Bmp);
Bmp.Canvas.Draw(4,0,Bmp);
end;
{$IFDEF FLX_NOPATTERN}
function CreateBmpPattern(const n, ColorFg, ColorBg: integer): TBitmap;
var
Ac: TCanvas;
begin
Result:=TBitmap.Create;
try
Result.Width:=8;
Result.Height:=8;
{$IFDEF FLX_CLX}
Result.PixelFormat:=pf32bit;
{$ELSE}
Result.PixelFormat := pfDevice; //for win95
{$ENDIF}
Ac:=Result.Canvas;
case n of
1: //No pattern
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,8,8));
end;
else //fill pattern //No pixel support on tcanvas, so we can't use patterns here.
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,8,8));
end;
end; //case
except
FreeAndNil(Result);
raise;
end;
end;
{$ELSE}
function CreateBmpPattern(const n, ColorFg, ColorBg: integer): TBitmap;
var
Ac: TCanvas;
x,y: integer;
begin
Result:=TBitmap.Create;
try
Result.Width:=8; //We just need a 4x4 bitmap, but windows95 does not like it.
Result.Height:=8;
{$IFDEF FLX_CLX}
Result.PixelFormat:=pf32bit;
{$ELSE}
Result.PixelFormat := pfDevice; //for win95
{$ENDIF}
Ac:=Result.Canvas;
case n of
1: //No pattern
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,8,8));
end;
2: //fill pattern
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,8,8));
end;
3: //50%
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,8,8));
for y:=0 to 7 do
for x:=0 to 3 do
Ac.Pixels[x*2+y mod 2,y]:=ColorFg;
end;
4: //75%
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorBg;
Ac.Pixels[2,1]:=ColorBg;
Ac.Pixels[0,2]:=ColorBg;
Ac.Pixels[2,3]:=ColorBg;
Fill8x8Image(Result);
end;
5: //25%
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg;
Ac.Pixels[2,1]:=ColorFg;
Ac.Pixels[0,2]:=ColorFg;
Ac.Pixels[2,3]:=ColorFg;
Fill8x8Image(Result);
end;
6: //Horz lines
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,4,2));
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,2,4,4));
Fill8x8Image(Result);
end;
7: //Vert lines
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,2,4));
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(2,0,4,4));
Fill8x8Image(Result);
end;
8: // \ lines
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg; Ac.Pixels[1,0]:=ColorFg;
Ac.Pixels[1,1]:=ColorFg; Ac.Pixels[2,1]:=ColorFg;
Ac.Pixels[2,2]:=ColorFg; Ac.Pixels[3,2]:=ColorFg;
Ac.Pixels[3,3]:=ColorFg; Ac.Pixels[0,3]:=ColorFg;
Fill8x8Image(Result);
end;
9: // / lines
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[2,0]:=ColorFg; Ac.Pixels[3,0]:=ColorFg;
Ac.Pixels[1,1]:=ColorFg; Ac.Pixels[2,1]:=ColorFg;
Ac.Pixels[0,2]:=ColorFg; Ac.Pixels[1,2]:=ColorFg;
Ac.Pixels[3,3]:=ColorFg; Ac.Pixels[0,3]:=ColorFg;
Fill8x8Image(Result);
end;
10: // diagonal hatch
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg; Ac.Pixels[1,0]:=ColorFg;
Ac.Pixels[0,1]:=ColorFg; Ac.Pixels[1,1]:=ColorFg;
Ac.Pixels[2,2]:=ColorFg; Ac.Pixels[3,2]:=ColorFg;
Ac.Pixels[2,3]:=ColorFg; Ac.Pixels[3,3]:=ColorFg;
Fill8x8Image(Result);
end;
11: // bold diagonal
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[2,0]:=ColorBg; Ac.Pixels[3,0]:=ColorBg;
Ac.Pixels[0,2]:=ColorBg; Ac.Pixels[1,2]:=ColorBg;
Fill8x8Image(Result);
end;
12: // thin horz lines
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,4,1));
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,1,4,4));
Fill8x8Image(Result);
end;
13: // thin vert lines
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,1,4));
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(1,0,4,4));
Fill8x8Image(Result);
end;
14: // thin \ lines
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg;
Ac.Pixels[1,1]:=ColorFg;
Ac.Pixels[2,2]:=ColorFg;
Ac.Pixels[3,3]:=ColorFg;
Fill8x8Image(Result);
end;
15: // thin / lines
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[3,0]:=ColorFg;
Ac.Pixels[2,1]:=ColorFg;
Ac.Pixels[1,2]:=ColorFg;
Ac.Pixels[0,3]:=ColorFg;
Fill8x8Image(Result);
end;
16: // thin horz hatch
begin
Ac.Brush.Color:=ColorFg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(1,1,4,4));
Fill8x8Image(Result);
end;
17: // thin diag
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg; Ac.Pixels[2,0]:=ColorFg;
Ac.Pixels[1,1]:=ColorFg;
Ac.Pixels[0,2]:=ColorFg; Ac.Pixels[2,2]:=ColorFg;
Ac.Pixels[3,3]:=ColorFg;
Fill8x8Image(Result);
end;
18: // 12.5 %
begin
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,4,4));
Ac.Pixels[0,0]:=ColorFg;
Ac.Pixels[2,2]:=ColorFg;
Fill8x8Image(Result);
end;
19: // 6.25 %
begin
//Not needed now. Result.Width:=8;
Ac.Brush.Color:=ColorBg;
Ac.FillRect(Rect(0,0,8,8));
Ac.Pixels[0,0]:=ColorFg;
Ac.Pixels[4,2]:=ColorFg;
Ac.Pixels[0,4]:=ColorFg;
Ac.Pixels[4,6]:=ColorFg;
end;
end; //case
except
FreeAndNil(Result);
raise;
end;
end;
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -