一张bmp图片,底色为白色,上面有一个椭圆,椭圆内部全为黑色,我求一种算法,结果要在在另一张同样大小的BMP图片的同样位置上,生成一个一模一样的椭圆,但内部为红色的。有几个难点:1 怎样确定椭圆在图片上的相对位置。2 怎样确定椭圆的大小及弧度?这个问题我想了三天了。顶者有分,希望有高手能把代码贴出来一下。谢谢了。

解决方案 »

  1.   

    图片只有白色和黑色,扫描所有的点,将黑色改成红色就可以了。const PixelCountMax=10000;
    type
      PRGBArray  = ^TRGBArray;
      TRGBArray  = array[0..PixelCountMax-1] of TRGBTriple;
    var Bitmap:TBitmap;
        p : PRGBArray;
        x, y: integer;
        c : array of array of TColor;
    begin
      Bitmap := TBitmap.Create;
      try
      Bitmap.LoadFromFile('c:\1.bmp');
      SetLength(c, Bitmap.Width, Bitmap.Height);
      Bitmap.PixelFormat :=  pf24bit;
      for y:=0 to Bitmap.Height-1 do
       begin
         p := PRGBArray(Bitmap.ScanLine[y]);
         for x:=0 to Bitmap.Width-1  do
         begin
           c[x,y]:= RGB(p[x].rgbtRed,p[x].rgbtGreen,p[x].rgbtBlue);
         end;
       end;
      for x:=0 to bitmap.Width-1 do
        for y:=0 to Bitmap.Height-1 do
         if c[x,y] = clBlack then
          Canvas.Pixels[x, y] := clRed
         else
          Canvas.Pixels[x, y] := c[x,y];
      finally
        Bitmap.Free;
     end;
    end;
      

  2.   

    谢谢老之,如果是椭圆的区域,嵌另一张图片进去呢?其实我发贴的目的是,想像photoshop的魔术棒一样得到一个区域。
      

  3.   

    把第一张bmp图片,透明色设置为黑色
    贴到第二张图片就可以了