203010朋友请进,送给你的礼物.(80分)

  • 主题发起人 主题发起人 卷起千堆雪tyn
  • 开始时间 开始时间

卷起千堆雪tyn

Unregistered / Unconfirmed
GUEST, unregistred user!
小小礼物送给你,谢谢 .

>以下程序在一个表单上放置一个Timer控件,设置Interval :=100;
>实现PhotoShop里的流动线效果.


unit n;

interface

uses
Windows,Forms,Graphics,Classes,ExtCtrls;

type
TF=class(TForm)
m:TTimer;
procedure mTimer(Sender:TObject);
end;

var
F:TF;
a:Byte;

implementation

{$R *.DFM}

procedure c(X,Y:Integer;t:TCanvas);stdcall;
begin
a:=a shl 1;
if a =0 then a:=1;
if (a and 224)>0 then
t.Pixels[X,Y]:=clWhite
else
t.Pixels[X,Y]:=clBlack;
end;

procedure TF.mTimer(Sender:TObject);
begin
LineDDA(0,0,333,333,@c,LongInt(Canvas));
end;

end.

>运行之后,有没有看见象蚂蚁在爬呢?
 
有意思,还你一个,下面的两个函数可以解决所有图片格式的流存储问题,再配上压缩就更好用了
const
GraphicClasses: array [0..11] of TGraphicClass
= (TBitmap, TIcon, TMetaFile, TJPEGImage, TGIFGraphic, TPCXGraphic,
TPPMGraphic, TPSDGraphic, TRLAGraphic, TSGIGraphic, TTargaGraphic,
TTIFFGraphic); //这里加上你所有可识别的图象格式

resourcestring
SInvalidGraphicClass = 'Invalid graphic class';

function CheckGraphicClass(AClassName: string): TGraphicClass;
var i: Integer;
begin
for i := 0 to High(GraphicClasses) do
begin
Result := GraphicClasses;
if SameText(AClassName, GraphicClasses.ClassName) then Exit;
end;
Result := nil;
end;

procedure SavePictureToStream(P: TPicture; Stream: TStream);
var
ImageNull: ByteBool;
CName: ShortString;
Position, Size: Int64;
begin
if (P.Graphic <> nil) and (CheckGraphicClass(P.Graphic.ClassName) = nil) then
raise Exception.CreateRes(@SInvalidGraphicClass);

ImageNull := (P.Graphic = nil) or P.Graphic.Empty;
Stream.Write(ImageNull, 1);
if not ImageNull then
begin
CName := P.Graphic.ClassName;
Stream.Write(CName[0], Length(CName) + 1);
Stream.Write(Size, 8);
Position := Stream.Position;
P.Graphic.SaveToStream(Stream);
Size := Stream.Size - Position;
Stream.Position := Position - 8;
Stream.Write(Size, 8);
Stream.Seek(0, soEnd);
end;
end;

procedure LoadPictureFromStream(P: TPicture; Stream: TStream);
var
ImageNull: ByteBool;
CName: PChar;
L: Byte;
C: TGraphicClass;
B: TBitmap;
TempStream: TMemoryStream;
Size: Int64;
begin
Stream.Read(ImageNull, 1);
if not ImageNull then
begin
Stream.Read(L, 1);
CName := StrAlloc(L + 1);
try
FillChar(CName^, L + 1, #0);
Stream.Read(CName^, L);
C := CheckGraphicClass(CName);
if C = nil then raise Exception.CreateRes(@SInvalidGraphicClass);
Stream.Read(Size, 8);
TempStream := TMemoryStream.Create;
try
TempStream.CopyFrom(Stream, Size);
TempStream.Seek(0, soBeginning);
P.Graphic := C.Create;
P.Graphic.LoadFromStream(TempStream);
finally
TempStream.Free;
end;
finally
StrDispose(CName);
end;
end
else begin
if P.Graphic <> nil then
begin
B := TBitmap.Create;
try
P.Graphic := B;
finally
B.Free;
end;
end;
end;
end;

 
接受答案了.
 
后退
顶部