在Image1中是全白的Bitmap
现提供一种Color
如何做,最简单的将Image变成那种颜色。
不能用一个点一个点的方法。
因为这种我会,我希望系统可以最快最简便的完成。

解决方案 »

  1.   

    如果不是24bit的真彩图,建议直接操作调色板。
      

  2.   

    以前给别人的代码:纠正8bit图到1bit时背景变红用的;有删节可能不好用// 其实最省事但是比较dirty的方法:直接开文件,seek到color table,改掉完事。
    procedure TForm1.BitBtn3Click(Sender: TObject);
    var
      bitmap: TBitmap;
      LogPalette: TMaxLogPalette;
      ...
    begin
      if openpicturedialog1.Execute then
      try
        // just show it out in Image1
        image1.Picture.LoadFromFile(openpicturedialog1.FileName);
        bitmap := TBitmap.Create;
        bitmap.Height := image1.Picture.Bitmap.Height;
        bitmap.Width := image1.Picture.Bitmap.Width;
        bitmap.PixelFormat := pf8bit;
        
        // do some thing    LogPalette.palVersion := $300;  //fixed, see MSDN
        LogPalette.palNumEntries := 2;  //two color, 1 bit
        //color1: black
        LogPalette.palPalEntry[0].peRed := 0;
        LogPalette.palPalEntry[0].peGreen := 0;
        LogPalette.palPalEntry[0].peBlue := 0 ;
        LogPalette.palPalEntry[0].peFlags := 0;
        //color2: white
        LogPalette.palPalEntry[1].peRed := 255;
        LogPalette.palPalEntry[1].peGreen := 255;
        LogPalette.palPalEntry[1].peBlue := 255;
        LogPalette.palPalEntry[1].peFlags := 0;
        bitmap.Palette := CreatePalette(PLogPalette(@LogPalette)^);
        bitmap.PixelFormat := pf1bit;    // show the converted bitmap; 
        image2.Picture.Bitmap.Assign(bitmap);
        // you may save bitmap to an file now;
      finally
        FreeAndNil(bitmap);
      end;
    end;
      

  3.   

    直接Image1.Picture.Bitmap.Canvas.Brush.Color := 你的Color;
    Image1.Picture.Bitmap.Canvas.FillRect(Rect(0,0,bmp宽度,bmp高度));不就可以了?