for y := 0 to newBmp.Height - 1 do  
    begin
        p := newBmp.scanline[y];
        for x := 0 to newBmp.Width - 1 do
        begin
            
            p[x*3]:=p[x*3]+2;
        end;这种方法,改变了p的值,就自动存到newBmp了,但如果改变了尺寸,每4个像素合成1个,该怎么做呢。

解决方案 »

  1.   

     我这样做:
    for y := 0 to newBmp.Height - 1 do 
         begin
            p := newBmp.scanline[y];
            for x := 0 to newBmp.Width - 1 do
            begin
                B[x][y]:=p[x*3];
                G[x][y]:=p[x*3+1];
                R[x][y]:=p[x*3+2];
            end;
         end;    for y := 0 to (newBmp.Height - 1) div 2 do  //动态数组下标从0开始
         begin
            New_p := newBmp.scanline[y];
            for x := 0 to (newBmp.Width - 1) div 2 do
            begin
                New_p[x*3]:=  (B[y*2][x*2]+B[y*2][x*2+1]+B[y*2+1][x*2]+B[y*2+1][x*2+1]) div 4;
                New_p[x*3+1]:=(G[y*2][x*2]+G[y*2][x*2+1]+G[y*2+1][x*2]+G[y*2+1][x*2+1]) div 4;
                New_p[x*3+2]:=(R[y*2][x*2]+R[y*2][x*2+1]+R[y*2+1][x*2]+R[y*2+1][x*2+1]) div 4;
            end;
         end;  
        Image2.Picture.Bitmap.Assign(newBmp);但显示时,左上脚1/4是缩小的图,其余3/4是原图。我特地换了个变量New_p呢,怎么消除原图啊。
      

  2.   

    这是因为其余3/4的画布上的像素只还是原来的值,你们没有把他清空。再加上一段清空的代码吧
    for y := (newBmp.Height - 1) div 2 to (newBmp.Height - 1) do //动态数组下标从0开始
      begin
      New_p := newBmp.scanline[y];
      for x := (newBmp.Height - 1) div 2 to (newBmp.Height - 1) do
      begin
      New_p[x*3]:= 255;
      New_p[x*3+1]:=255;
      New_p[x*3+2]:=255;
      end;
      end;