位图快速黑白化Bitmap.PixelFormat:=pf1bit ... 上面的图片可能受,前一次的.PixelFormat:=pf1bit 的影响.;现在重新测试了,每次都是这个效果.原图是: 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 唉,不知道怎么回事.我只是代码换下行,居然又变化了. Image1.Picture.Bitmap.PixelFormat:=pf1bit; Panel1.Color:=RGB(0,255,255); 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; bmp.PixelFormat:= pfDevice; bmp.PixelFormat:= pf1bit;这样就可以 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文件,第一次是褐色的,然后就一直灰黑色...不知道为什么. 你的问题在于你应该先加载图片,然后再设置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; 的确可以!!!这什么原理呢,其他的pf24bit 和pf32bit都不行,非得pfdevice呢?? cxgrid 如何关联列 如果将行记录导出文本文件(txt) 对Delphi挺多控件不熟,哪些网站有较为全面的介绍控件的属性、方法等的资料? 根据系统时间自动生成编号问题 求助 能否告诉我一个批量修改unit文件名的方法????????? 写好了的包和存储过程,怎么调试才知道是可用的 急!高分求救!我可以ping通SQLServer数据库服务器,客户端ODBC别名却无法连接上,大概是什么原因? 关于锁鼠标和键盘的小问题! 如何通过delphi在Excel中添加一个工作薄,使用模板 用delphi做个service application,开机启动外部程序,可行不? 怎样让程序开机时自启动?
Panel1.Color:=RGB(0,255,255);
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;
bmp.PixelFormat:= pf1bit;
这样就可以
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文件,第一次是褐色的,然后就一直灰黑色...不知道为什么.
//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;