上面的图片可能受,前一次的.PixelFormat:=pf1bit 的影响.;
现在重新测试了,每次都是这个效果.原图是:

解决方案 »

  1.   

    唉,不知道怎么回事.我只是代码换下行,居然又变化了.  Image1.Picture.Bitmap.PixelFormat:=pf1bit;
      Panel1.Color:=RGB(0,255,255);
      

  2.   


    var
      p: PByteArray;
      Gray, x, y: Integer;
      Bmp: TBitmap;
    begin
      Bmp := TBitmap.Create;
      Bmp.LoadFromFile('你的bmp文件');
      Bmp.PixelFormat := pf24Bit;
      randomize;  for y := 0 to Bmp.Height - 1 do
      begin
        p := Bmp.scanline[y];
        for x := 0 to Bmp.Width - 1 do
        begin
          //一个象素点三个字节
          Gray := Round(p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x
            * 3] * 0.11);
          if gray > 128 then //全局阀值128
          begin
            p[x * 3] := 255;
            p[x * 3 + 1] := 255;
            p[x * 3 + 2] := 255;
          end
          else
          begin
            p[x * 3] := 0;
            p[x * 3 + 1] := 0;
            p[x * 3 + 2] := 0;
          end;
        end;
      end;
      // 显示二值化后的bmp
      Canvas.Draw(10,10,Bmp);
      Bmp.Free;
    end;
      

  3.   

    bmp.PixelFormat:= pfDevice; 
    bmp.PixelFormat:= pf1bit;
    这样就可以
      

  4.   


    pfDevice 应该是当前系统的彩色位数. 相当于设置高点,再变低的.但是还是不是黑白色啊.
    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      OpenPictureDialog1.Execute;
      Image1.Picture.Bitmap.PixelFormat:=pfDevice;
      Image1.Picture.Bitmap.FreeImage;
      Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
      Image1.Picture.Bitmap.PixelFormat:=pf1bit;
    end;一次运行,然后多次打开不同的bmp文件,第一次是褐色的,然后就一直灰黑色...不知道为什么.
      

  5.   

    你的问题在于你应该先加载图片,然后再设置PixelFormat  OpenPictureDialog1.Execute;
      //Image1.Picture.Bitmap.PixelFormat:=pfDevice;
      Image1.Picture.Bitmap.FreeImage;
      Image1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);
      Image1.Picture.Bitmap.PixelFormat:=pfDevice;
      Image1.Picture.Bitmap.PixelFormat:=pf1bit;
      

  6.   

    的确可以!!!这什么原理呢,其他的pf24bit 和pf32bit都不行,非得pfdevice呢??