如题 
给TBitmap变量填充指定的纯色!!!!
急 在线等

解决方案 »

  1.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      bmp:Tbitmap;
      i,j:integer;
    begin
      bmp:=Tbitmap.Create;
      bmp.Width:=100;
      bmp.Height:=100;
      for i:=0 to bmp.Width-1 do
        for j:=0 to bmp.Height-1 do
          bmp.Canvas.Pixels[i,j]:=clred;
      bmp.SaveToFile('d:\tmp.bmp');
      bmp.free;
    end;
      

  2.   

    我就郁闷了 怎么还是不行呢'?在帮忙看看...
    var
      i,j:integer;
      bmp:tbitmap;
    begin
      if colordialog1.Execute then
        begin
          inic.WriteString('图层属性',t+'透空的颜色值',colortostring(colordialog1.Color));
          bmp:=Tbitmap.Create;
          bmp.Width:=13;
          bmp.Height:=12;
          for i:=0 to bmp.Width-1 do
             for j:=0 to bmp.Height-1 do
                bmp.Canvas.Pixels[i,j]:=clred;
          SpeedButton26.Glyph:=bmp;
          bmp.Free;
        end;
    end;
      

  3.   

    var
      i,j:integer;
      bmp:tbitmap;
    begin
      if colordialog1.Execute then
        begin
          inic.WriteString('图层属性',t+'透空的颜色值',colortostring(colordialog1.Color));
          bmp:=Tbitmap.Create;
    with  bmp do
    begin
          Width:=13;
          Height:=12;
          Canvas.Brush.Color:=clRed;
          Canvas.FillRect(Canvas.ClipRect);
          SpeedButton26.Glyph:=bmp;
          Free;
    end;
        end;
    end;
      

  4.   

    楼上的哥们!!!!
    和一楼的效果完全一样...
    保存成文件可以.但是直接赋值给SpeedButton26.Glyph就是空白....什么也没有!!!
    在帮下忙可以不 郁闷一早上了.
      

  5.   

    你可以将bmp:tbitmap声明成全局,关闭窗体时在释放
    或窗体上放一个image组件,image1.canvas.pixels[i,j]:=clred;SpeedButton26.Glyph:=image1.Picture.Bitmap;
      

  6.   

    var
      i,j:integer;
      bmp:tbitmap;
    begin
      if colordialog1.Execute then
        begin
          inic.WriteString('图层属性',t+'透空的颜色值',colortostring(colordialog1.Color));
          bmp:=Tbitmap.Create;
          bmp.Width:=11;
          bmp.Height:=11;
          for i:=1 to bmp.Width-2 do
             for j:=1 to bmp.Height-2 do
                bmp.canvas.pixels[i,j]:=colordialog1.Color;
          SpeedButton26.Glyph:=bmp;
          bmp.Free;
        end;
    end;谢谢两位 这才是正确答案 BMP大小的问题....for i:=1 to bmp.Width-2 这就对了 或 for i:=1 to bmp.Width-1 都行 for i:=0 to bmp.Width-2也许 但是 for i:=0 to bmp.Width-1就不行 为什么肯定知道了哇...