【问题标题】:mfc, can any one help with an algorithm for airbrush, i just can't understand how to do itmfc,任何人都可以帮助使用喷枪算法,我只是不明白该怎么做
【发布时间】:2011-02-12 13:56:52
【问题描述】:

有没有办法像 mspaint 中的喷枪工具一样逐点填充椭圆或矩形?

我找不到一种方法来创建一个空的矩形或椭圆,然后逐个像素地填充它们或以圆形方式在屏幕上设置随机像素......

我可以告诉 setPixel 填充一个 dcellipse 或类似的东西吗?

10 倍

【问题讨论】:

    标签: visual-c++ mfc


    【解决方案1】:

    您需要使用CRgn 创建一个区域,然后使用SelectClipRgn 在您的CDC 中选择它作为剪辑区域。然后,您可以使用 CDC::SetPixel 在形状的边界矩形内的任意位置设置随机像素,并且只会绘制剪切区域内的像素。

    请注意,这会很慢,并且每次窗口绘制时都需要重做(例如当另一个窗口被拖动到它上面时)。

    【讨论】:

      【解决方案2】:

      在您的“制作随机像素”循环中,如果像素在您想要的圆圈之外,则只需排除它。

      num_pixels = 20; // how many pixels
      circle_radius = 32;  // 32-pixel radius, or whatever you'd like
      circle_radius2 = circle_radius * circle_radius;
      
      while (num_pixels-- > 0)
      {
          // get a random number between (-circle_radius / 2, circle_radius / 2)
          pixel_x = rand(circle_radius) - circle_radius / 2; 
          pixel_y = rand(circle_radius) - circle_radius / 2; 
      
          // compute squared distance between generated pixel and radius, 
          // exclude if out of range
          if ( (center_x - pixel_x) * (center_x - pixel_x) + 
               (center_y - pixel_y) * (center_y - pixel_y) > circle_radius2 )
              continue; // generate another pixel
      
          // do stuff with pixel
      } 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-06-16
        • 2021-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-07
        • 2022-07-19
        • 1970-01-01
        相关资源
        最近更新 更多