在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
TBitmap 主要成员:
{ 方法 } SetSize(); //设置大小 Clear(); //取消, 就是用指定颜色覆盖 ClearRect(); //覆盖指定矩形范围, 默认覆盖为透明色 BitmapChanged(); //刷新改变 IsEmpty(); //是否为空 UpdateHandles(); //将 Handles 数组中的对象标记为需要更新 AddFreeNotify(); //将指定对象添加到可以释放的列表; 这一般是针对添加到 Handles 中的对象 RemoveFreeNotify(); //释放指定对象; 这一般是针对添加到 Handles 中的对象 Rotate(); //旋转角度 FlipHorizontal(); //水平翻转 FlipVertical(); //垂直翻转 InvertAlpha(); //翻转透明度, 只适于透明图片 FillColor(); //填充遮罩色, 用于透明图片 CreateMask(); //建立蒙版; 是从 TBitmap 中把各像素的透明度提取为一个数组, 返回数组指针 ApplyMask(); //添加蒙版, 其参数应该是有 CreateMask() 建立的 CreateThumbnail(); //建立略缩图 LoadFromFile(); //从文件载入 LoadFromStream(); //从流中载入 LoadThumbnailFromFile(); //从文件载入为略缩图 SaveToFile(); //保存到文件 SaveToStream(); //保存到流 HandleRemove(); //从 Handles 数组移除对象, 并没有释放 HandleAdd(); //添加对象到 Handles 数组 HandleExists(); //判断指定对象是否已添加到 Handles 数组 { 属性 } Width : Integer; //宽 Height : Integer; //高 Handles[AItem: Pointer] : Pointer; //访问 Handles 中的对象, 索引是指针; 写入前需要先 HandleAdd(); HandlesNeedUpdate[AItem: Pointer] : Boolean; //判断 Handles 中的指定对象是否需要更新 Canvas : TCanvas; //获取绘图表面 Pixels[X, Y: Integer] : TAlphaColor; //获取或设置指定位置的颜色值 ScanLine[Y: Integer] : PAlphaColorArray; //获取一条横线上的像素数组的指针 StartLine : PAlphaColorArray; //获取像素数组的指针 ResourceBitmap : TBitmap; //该属性应该是内部使用的 StyleLookup : string; //这应该是和控件的造型相关的, 暂不知 TBitmap 要它干嘛 { 事件 } OnChange: TNotifyEvent; //
procedure TForm1.Button1Click(Sender: TObject); var bit: TBitmap; begin bit := TBitmap.Create(0, 0); ShowMessage(BoolToStr(bit.IsEmpty, True)); bit.SetSize(100, 100); ShowMessage(BoolToStr(bit.IsEmpty, True)); bit.Clear(claRed); Image1.Bitmap.Assign(bit); bit.Free; end;
procedure TForm1.FormCreate(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); Image1.WrapMode := TImageWrapMode.iwFit; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Rotate'); Image1.Bitmap.Rotate(60); ShowMessage('FlipHorizontal'); Image1.Bitmap.FlipHorizontal; ShowMessage('FlipVertical'); Image1.Bitmap.FlipVertical; end;
procedure TForm1.FormCreate(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); //要个透明图片 Image1.WrapMode := TImageWrapMode.iwFit; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Image1.Bitmap.FillColor($800000FF); // Image1.Bitmap.FillColor($FF0000FF); end;
procedure TForm1.FormCreate(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); //要个透明图片 Image1.WrapMode := TImageWrapMode.iwFit; end; end; procedure TForm1.Button1Click(Sender: TObject); var bit: TBitmap; bitAs: PByteArray; begin bit := TBitmap.Create(0, 0); bit.Assign(Image1.Bitmap); //从 Image1 复制 TBitmap bitAs := bit.CreateMask; Image1.Bitmap.Clear(claBlue); Image1.Bitmap.ApplyMask(bitAs); bit.Free; end;
procedure TForm1.FormCreate(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); //要个透明图片 Image1.WrapMode := TImageWrapMode.iwFit; end; end; //点击按钮调整图像的透明度 procedure TForm1.Button1Click(Sender: TObject); var bit: TBitmap; bts: PAlphaColorArray; i: Integer; j: Integer; begin bit := TBitmap.Create(0, 0); bit.Assign(Image1.Bitmap); bts := bit.StartLine; for i := 0 to bit.Width - 1 do for j := 0 to bit.Height - 1 do TAlphaColorRec(bts[i*j]).A := TAlphaColorRec(bts[i*j]).A div 2; //现在通过数组指针可以直接索引元素了, 太好 Image1.Bitmap.Assign(bit); bit.Free; end;
procedure TForm1.FormCreate(Sender: TObject); begin if OpenDialog1.Execute then begin Image1.Bitmap.LoadFromFile(OpenDialog1.FileName); //要个透明图片 Image1.WrapMode := TImageWrapMode.iwFit; Image1.Position.X := 0; Image1.Position.Y := 0; Image1.Width := Image1.Bitmap.Width; Image1.Height := Image1.Bitmap.Height; end; end; procedure TForm1.Button1Click(Sender: TObject); var bit: TBitmap; W,H,i,j: Integer; R: TRectF; begin W := Trunc(Image1.Width); H := Trunc(Image1.Height); bit := TBitmap.Create(W div 2, H div 2); for i := 0 to W - 1 do for j := 0 to H - 1 do begin if Odd(i) and Odd(j) then //复制单数行以缩小图像一倍 bit.Pixels[i div 2, j div 2] := Image1.Bitmap.Pixels[i, j]; end; Image1.Width := bit.Width; Image1.Height := bit.Height; Image1.Bitmap.Assign(bit); Realign; bit.Free; end;
var bit1,bit2,bit3: TBitmap; procedure TForm1.FormCreate(Sender: TObject); begin bit1 := TBitmap.Create(100, 100); bit2 := TBitmap.Create(100, 100); bit3 := TBitmap.Create(100, 100); bit1.Clear(claRed); bit2.Clear(claGreen); bit3.Clear(claBlue); Image1.Width := 100; Image1.Height := 100; Image1.Bitmap.HandleAdd(Button1); Image1.Bitmap.Handles[Button1] := bit1; Image1.Bitmap.HandleAdd(Button2); Image1.Bitmap.Handles[Button2] := bit2; Image1.Bitmap.HandleAdd(Button3); Image1.Bitmap.Handles[Button3] := bit3; Button2.OnClick := Button1.OnClick; Button3.OnClick := Button1.OnClick; end; procedure TForm1.Button1Click(Sender: TObject); begin Image1.Bitmap := Image1.Bitmap.Handles[Sender]; end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论