我在背景为绿色的图片的canvas上画了一条红色的线,那么这条线所覆盖的象素的颜色会改变吗?
假如以前的canvas.pixels=clgreen,那么这个象素点被红色直线画上之后,他的颜色值能是clRed吗?在线等!

解决方案 »

  1.   

    与 pen.mode 有关各位如果方便,请给我儿子投一票
    http://www.nutricia.com.cn/vote.asp?id=736
    谢谢
      

  2.   

    to: victorchen_2000(微力) 
     您说的pen.mode指的是什么,pen.mode在什么情况下才能改变覆盖的象素的颜色呢?请帮忙
     
     再请教您个问题:我在一幅底色为绿色的图片上,用红色画笔圈定了一个区域,我想把这个红色画笔圈定的边界作为剪裁的边界,请问我怎样才能确定每一行上的红色边界点呢,也就是说,怎么写代码才能表示这个红色点就是边界点呢?我不知道算法,请您帮我想想啊,感激不尽了。
      

  3.   

    to: victorchen_2000(微力) 
     您的儿子很帅哟,呵呵!投票成功!
      

  4.   

    通常 pmCopy.
    pmBlack Always black
    pmWhite Always white
    pmNop Unchanged
    pmNot Inverse of canvas background color
    pmCopy Pen color specified in Color property
    pmNotCopy Inverse of pen color
    pmMergePenNot Combination of pen color and inverse of canvas background
    pmMaskPenNot Combination of colors common to both pen and inverse of canvas background.
    pmMergeNotPen Combination of canvas background color and inverse of pen color
    pmMaskNotPen Combination of colors common to both canvas background and inverse of pen
    .......
    很多,看 TPen 的 mode 的帮助.
      

  5.   

    不是覆盖,是替换,rgb的值改变成现在的
      

  6.   

    我在一幅底色为绿色的图片上,用红色画笔圈定了一个区域,我想把这个红色画笔圈定的边界作为剪裁的边界,请问我怎样才能确定每一行上的红色边界点呢,也就是说,怎么写代码才能表示这个红色点就是边界点呢?
    if canvas.pixels[x,y]:=clred then
    //用循环走完全部的x,y组合,把红色点找出来。
    http://blog.csdn.net/whbo
    这里应该还有关于图形的几句代码,参考下
      

  7.   

    to: bill_anson(铱星)
      怎样用区域的知识啊,教教我吧!
      

  8.   

    to: whbo(王红波(年轻人,要有所作为)) 
     我的意思把红色点以外的象素颜色都变成白色,内部点保留,代码该怎么写呀? 可否助我一臂之力,万分感激
      

  9.   

    你明白什么是Canvas吗?它只是逻辑上存在的,而非实际上的位图。它就像CDC这样封装GDI的class,GDI可以操作DIB/DDB。对Canvas本身来说根本不存在像素的概念,像素是DIB/DDB上的。如果你是说DIB,自然改变,如果是DDB你和你理解的那种位图像素根本是两个概念。
      

  10.   

    //下面的过程是一个例子:将thePoint的位置作为基点,填充任何闭合图形。
    //就好像在图上点了一下,所有与该点相同的区域都会变成 (theColor)设定的颜色。//theCanvas: 画板。     theColor: 填充的颜色.   thePoint: 基点。procedure FillFlood(const theCanvas: TCanvas; const theColor: TColor;
                      const thePoint: TPoint);
    begin
        theCanvas.Brush.Color := theColor;          //      //最重要的函数。  API函数. 
        ExtFloodFill(theCanvas.Handle, thePoint.X, thePoint.Y,
                              GetPixel(theCanvas.Handle, thePoint.X, thePoint.Y), 4);
        theCanvas.Brush.Style := bsClear;
        theCanvas.Pixels[thePoint.X, thePoint.Y] := theColor;end;//看你的悟性了
      

  11.   

    回复人: Kvci(蛮) 
     我就想按照你说的方法做,可是我这个红色点怎么找到呢,我发现在一幅图片上画红色的线,可显示出来的却不是红色线,您说,是不是线下面的象素颜色和当前红色混合成别的颜色了呢,画线的颜色能改变它下面象素的颜色值吗?在线等待指导!还有,如果用scanline方法,那当前象素的颜色该怎样表示呢,如果象素颜色是红色的话,
     p:prgbtriple;
     p[x].rgbtblue=
     p[x].rgbtgreen=
     p[x].rgbtred=  等号右边的值该怎样赋值呢,黑色用0表示,白色用255表示,那红色用什么表示,红色还分好多种呢,该写什么呀。如果不这样赋值,该怎样呢!快指导指导我吧!
      

  12.   

    bill_anson(铱星) 
    对象素操作很慢的,每次运行都结束不了操作,能和扫描线方法结合着用吗?等待指导!
      

  13.   

    在一幅图片上画红色的线,可显示出来的却不是红色线,您说,是不是线下面的象素颜色和当前红色混合成别的颜色了呢,画线的颜色能改变它下面象素的颜色值吗?
    设置 TPen 的 mode 为 pmCopy。你想采用种子填充方法吧,那需要用到堆栈的,递归。我劝你还是采用 ExtFloodFill 来填充整个区域吧。
    种子填充需要对每个象素操作。
    procedure FillColors(FBitmap: TBitmap; FWidth, FHeight, Xs,
       Ys: integer; OldColor, NewColor: Byte);
    type
       stackfield = record
          xl, xr, y: integer;
       end;
    var
       i, X, Xl, Xr, p_Xl, p_Xr, signed_Y: integer;
       P: PByteArray;
       stack: array of stackfield;
       procedure set_stack_empty();
       begin      setlength(stack, 1);
          stack[0].y := 0;
       end;
       function stack_not_empty(): boolean;
       begin
          if stack[0].y = 0 then
             result := false
          else
             result := true;
       end;
       procedure push(xl, xr, yd: integer);
       begin
          stack[0].y := stack[0].y + 1;
          if stack[0].y > (length(stack) - 1) then
             setlength(stack, length(stack) + 1);
          stack[stack[0].y].xl := xl;
          stack[stack[0].y].xr := xr;
          stack[stack[0].y].y := yd
       end;
       procedure pop(var xl: integer; var xr: integer; var yd: integer);
       begin
          if stack[0].y > 0 then
             begin
                xl := stack[stack[0].y].xl;
                xr := stack[stack[0].y].xr;
                yd := stack[stack[0].y].y;
                stack[0].y := stack[0].y - 1;
                setlength(stack, length(stack) - 1);
             end;
       end;
    begin
       //Fwidth,FHeight为位图的宽度和高度
       set_stack_empty; //////////
       P := fbitmap.ScanLine[Ys];
       i := Xs;
       if P[i] = Newcolor then
          exit;
       while (P[i] = OldColor) do
          begin
             P[i] := NewColor;
             i := i + 1;
             if i = fbitmap.Width then
                break;
          end;
       Xr := i - 1;
       i := Xs - 1;
       while (P[i] = OldColor) do
          begin
             P[i] := NewColor;
             i := i - 1;
             if i = -1 then
                break;
          end;
       Xl := i + 1;
       if ys > 0 then
          push(Xl, Xr, -(Ys - 1));
       if ys < fbitmap.height - 1 then
          push(Xl, Xr, (Ys + 1));
       while stack_not_empty do
          begin
             pop(p_Xl, p_Xr, signed_Y);
             //y:=abs(signed_Y);
             P := fbitmap.scanline[abs(signed_y)];
             if (P[p_Xl] = OldColor) then //xl处是oldcolor时
                if p_xl > 0 then
                   begin
                      x := p_Xl - 1; //,xl非边界,否则将会出边界
                      while (P[x] = OldColor) do
                         begin
                            P[x] := NewColor;
                            x := x - 1;
                            if x = -1 then
                               break;
                         end;
                      Xl := x + 1;
                      x := p_Xl;
                   end
                else
                   begin
                      xl := 0; //   左边界已是0  时,新的xl自然取0
                      x := p_xl;
                   end
             else
                begin
                   x := p_Xl;
                   //  否则xl处非oldcolor,xl的左邻点不为olodcolor时,xl的右邻点可能为oldcolor时 ,向右找xl
                   if ((x > 0) and (p[x - 1] <> oldcolor)) or (x = 0) then
                      begin
                         while (p[x] <> OldColor) do
                            begin
                               x := x + 1;
                               if x = fbitmap.Width then
                                  begin
                                     x := x + 1;
                                     break;
                                  end;
                            end;
                         xl := x;
                      end
                   else if p_xl > 0 then
                      //否则xl 的左邻点是oldcolor时,先考虑左边,向左找xl
                      begin
                         x := p_Xl - 1;
                         while (P[x] = OldColor) do
                            begin
                               P[x] := NewColor;
                               x := x - 1;
                               if x = -1 then
                                  break;
                            end;
                         Xl := x + 1;
                         x := p_Xl;
                      end
                   else
                      begin
                         xl := 0;
                         x := p_xl;
                      end            end;
             while x <= (p_Xr + 1) do
                begin
                   while (p[x] = OldColor) do
                      begin
                         p[x] := NewColor;
                         x := x + 1;
                         if x = fbitmap.Width then
                            begin
                               break;
                            end;
                      end;
                   Xr := x - 1;
                   if (abs(signed_y - 1) <= (fbitmap.Height - 1)) and (abs(signed_y - 1)
                      >= 0) then
                      begin
                         if (Xl <= p_Xl - 1) then
                            push(xl, p_Xl - 1, -(signed_y - 1));
                         if (Xr >= p_Xr + 1) then
                            push(p_xr + 1, xr, -(signed_y - 1));
                      end;
                   if (abs(signed_y + 1) <= (fbitmap.Height - 1)) and (abs(signed_y + 1)
                      >= 0) then
                      push(Xl, Xr, signed_y + 1);
                   if x = fbitmap.Width then
                      x := X + 1;
                   if x <= (fbitmap.width - 1) then
                      while (x <= p_xr + 1) and (p[x] <> OldColor) do
                         begin
                            x := x + 1;
                            if x = fbitmap.Width then
                               begin
                                  x := x + 1;
                                  BREAK;
                               end;                     end;
                   Xl := x;
                end;
          end;
       // Fbitmap.invalidate;
    end;
      

  14.   

     p:prgbtriple;
     p[x].rgbtblue= clBlue  //蓝色
     p[x].rgbtgreen= clGreen //绿色
     p[x].rgbtred= clRed   //红色 
    设置 TPen 的 mode 为 pmCopy。
     self.Canvas.Pen.Mode := pmCopy;
      

  15.   

    谢谢bill_anson(铱星) 
       我受益匪浅,可要是把边界外的区域剪裁掉,该怎么做呢,还能用种子填充了吗?请指示!!!
      

  16.   

    好久没上网了。
    关于把边界外的区域剪裁掉:利用区域的相关知识。Rgn    SelectClipRgn