要测试好使得!!!

解决方案 »

  1.   

    参考 this :procedure TForm1.Button1Click(Sender: TObject);varlo:tbitmap;ij:integer;kl:longint;rrggbb:byte;res:byte;beginlo:=tbitmap.create;lo.Width:=image1.Width;lo.height:=image1.height;ProgressBar1.Max:=image1.Width+1;for i:=0 to image1.Width+1 dobeginfor j:=0 to image1.height+1 dobeginkl:=ColorToRGB(image1.Canvas.Pixels[ij]);rr:=byte(kl);gg:=byte(kl shr 8);bb:=byte(kl shr 8);res:=(rr+gg+bb) div 3;lo.Canvas.Pixels[ij]:=rgb(resresres);end;ProgressBar1.Position:=i;end;//for doimage1.Canvas.Draw(00lo);lo.free;end;
    the principle on which the code work is actually very simplewhat is happening is that when you evaluete a color variable you will see that it consists of 4 parts. red green blue and windows pallete info this is split up like thisFF FF FF FFPalletteinfo blue green redwhen the bluegreen and red values are added together and are devided by 3 you will always get a grey value.This procedure works by moving the value we want to rightand then typecasting it to a byte. When we typcast something the we start with the least significant bit and work our way up until it is equal in size to the variable we are typecasting it.if we look at a binary representation it looks like this1111 1111 1111 1111 1111 1111 1111 1111 this is white1111 1111 1111 1111 0000 0000 0000 0000 this is blue{byte }when a value like the above is shr the following happensit changes to:0000 0000 1111 1111 1111 1111 0000 0000 this is now yellow
      

  2.   

    //有vb源码下载吗?可以运行的,这个我看不太懂这段程序是delphi代码,它满足不了你的要求