如题

解决方案 »

  1.   

    刚前两天做了,把源代码发给你把
    思路: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;