哈哈镜局部放大缩小图像处理算法

在网上找了很多,没有找到比较合适的,所以决定自己在前人的基础上进行一些改善。

   
      protected  static Bitmap change2bitmap(Bitmap mbitmap) {
          int width = mbitmap.getWidth();
          int height = mbitmap.getHeight();
          int pixR = 0;
          int pixG = 0;
          int pixB = 0;
          int newR = 0;
          int newG = 0;
          int radius=700;//半径
          double dis =0.0;
          int newB = 0;
          int buf[] =new int[width * height];
          int centerX = 500;
          int centerY =1100;//圆心坐标
          int pixels[]=new int[width * height];
         mbitmap.getPixels(buf, 0, width, 0, 0, width, height);
          for (int i = 0; i < width; i++)
          {
              for (int j = 0; j < height; j++)
              {
                  int arrl_color = buf[j * width + i];
                  pixR = red(arrl_color);
                  pixG = green(arrl_color);
                  pixB = blue(arrl_color);
                  newR = pixR;
                  newG = pixG;
                  newB = pixB;
                   int   distance =  ((centerX - i) * (centerX - i) + (centerY - j) * (centerY - j));
                  dis=Math.sqrt(distance);
                  if (distance <= radius * radius)
                  {

                      int src_x1 = i - centerX;
                      int src_y1 = j - centerY;
                      int  src_x = (int)((dis/radius /2+0.5)*src_x1);
                      int  src_y = (int)((dis/radius /2+0.5)*src_y1);
                      src_x = src_x+ centerX;
                      src_y = src_y + centerY;
                      int src_color = buf[src_y * width + src_x];
                      newR = red(src_color);
                      newG = green(src_color);
                      newB = blue(src_color);

                  }

                  newR = Math.min(255, Math.max(0, newR));
                  newG = Math.min(255, Math.max(0, newG));
                  newB = Math.min(255, Math.max(0, newB));
                  pixels[width * j + i] = Color.argb(255, newR, newG, newB);
              }
          }



          mbitmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_4444);
          return mbitmap;


      }

  }

重点代码如下:
int src_x1 = (int) ((float) (i - centerX) );
int src_y1 = (int) ((float) (j - centerY)
int src_x = (int)((dis/radius /2+0.5)*src_x1);
int src_y = (int)((dis/radius /2+0.5)*src_y1);
src_x = src_x+ centerX;
src_y = src_y + centerY;
算法主要用到的还是一元二次方程,
相比较之前算法扩散范围变小,
扩散幅度由一元二次方程A值进行调控。
未调整前:
哈哈镜局部放大缩小图像处理算法_第1张图片
调整后:
哈哈镜局部放大缩小图像处理算法_第2张图片

你可能感兴趣的:(哈哈镜局部放大缩小图像处理算法)