读入jpg或gif或bmp,转换成2色bmp,改如何做? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 刚前两天做了,把源代码发给你把思路:1转换为Bmp图片,2二值化图片】function Ico2Bitmap(IcoPic: TIcon): TBitmap;begin Result := TBitmap.Create; Result.Width := IcoPic.Width; result.Height := IcoPic.Height; Result.PixelFormat := pf24bit; Result.Canvas.Draw( 0, 0, IcoPic );end;function Jpg2Bitmap(JpgPic: TJpegImage): TBitmap;begin Result := TBitmap.Create; Result.PixelFormat := pf24bit; Result.Assign( JpgPic );end;function Wmf2Bitmap(WmfPic: TMetaFile): TBitmap;begin Result := TBitmap.Create; Result.Height := WmfPic.Height; Result.Width := WmfPic.Width; Result.PixelFormat := pf24bit; Result.Canvas.Draw( 0, 0, WmfPic );end;===================================== //---------------------------------------------------------------------------- //函数名 : BitmapDuality //功 能 : 图像二值化处理 //参 数 : 输 入 Value 二值化阀值 // 返 回 Bitmap 要二值化图片 //开发人 : 刘卫兵 //开发时间: 2008.2.21 //----------------------------------------------------------------------------procedure BitmapDuality( Value: integer; Bitmap: TBitmap );var P : pByteArray; x, y : integer; Gray : byte;begin //24位位图处理 Bitmap.PixelFormat := pf24bit; //产生随机数 Randomize; For Y:= 0 to Bitmap.Height -1 do begin P := Bitmap.ScanLine[ Y ]; For X := 0 to Bitmap.Width -1 do begin //计算YUV灰度值 一个像素点3个字节 Gray := Round( P[ x * 3 + 2] * 0.3 + P[ x * 3 + 1] * 0.59 + P[ x * 3] * 0.11 ); if Gray > Value then 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;end; 请教怎么取消SetForegroundWindow的效果? 高手指点:excel数据倒入oracle中 如何播放内存中的wav文件? 谁会用visual graph我们公司想找个回用VG的图形控件开发人员 10分一个小问题,关于变量定义 如何自动生成助记码 各位帮帮忙.有分! DELPHI好书? 帮帮忙吧:ADO访问Access的问题!谢谢!! 请问:如何用API得到一个指定目录的所有文件 哪位高手指导下关于跳转到下一窗体的问题? unit1.~dfm unit1.~pas pro.~dpr 这是什么
思路:1转换为Bmp图片,2二值化图片】
function Ico2Bitmap(IcoPic: TIcon): TBitmap;
begin
Result := TBitmap.Create;
Result.Width := IcoPic.Width;
result.Height := IcoPic.Height;
Result.PixelFormat := pf24bit;
Result.Canvas.Draw( 0, 0, IcoPic );
end;function Jpg2Bitmap(JpgPic: TJpegImage): TBitmap;
begin
Result := TBitmap.Create;
Result.PixelFormat := pf24bit;
Result.Assign( JpgPic );
end;function Wmf2Bitmap(WmfPic: TMetaFile): TBitmap;
begin
Result := TBitmap.Create;
Result.Height := WmfPic.Height;
Result.Width := WmfPic.Width;
Result.PixelFormat := pf24bit;
Result.Canvas.Draw( 0, 0, WmfPic );
end;
=====================================
//----------------------------------------------------------------------------
//函数名 : BitmapDuality
//功 能 : 图像二值化处理
//参 数 : 输 入 Value 二值化阀值
// 返 回 Bitmap 要二值化图片
//开发人 : 刘卫兵
//开发时间: 2008.2.21
//----------------------------------------------------------------------------
procedure BitmapDuality( Value: integer; Bitmap: TBitmap );
var
P : pByteArray;
x, y : integer;
Gray : byte;
begin
//24位位图处理
Bitmap.PixelFormat := pf24bit;
//产生随机数
Randomize;
For Y:= 0 to Bitmap.Height -1 do
begin
P := Bitmap.ScanLine[ Y ];
For X := 0 to Bitmap.Width -1 do
begin
//计算YUV灰度值 一个像素点3个字节
Gray := Round( P[ x * 3 + 2] * 0.3 + P[ x * 3 + 1] * 0.59 + P[ x * 3] * 0.11 );
if Gray > Value then
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;
end;