Foxtable(狐表)用户栏目专家坐堂 → 如何实现图片的扭曲变形?如图?


  共有4114人关注过本帖树形打印复制链接

主题:如何实现图片的扭曲变形?如图?

帅哥哟,离线,有人找我吗?
lyfxybc
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
如何实现图片的扭曲变形?如图?  发帖心情 Post By:2015/3/23 20:09:00 [显示全部帖子]

如何实现图片的扭曲变形?如图?

代码如何写

 

 


图片点击可在新窗口打开查看此主题相关图片如下:32192195_9.jpg
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/3/24 11:51:00 [显示全部帖子]

未搜到代码

 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/3/25 11:50:00 [显示全部帖子]

有vb.net代码的老师们是否可以完成以下

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/3/25 17:49:00 [显示全部帖子]

谢谢

 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/3/26 12:25:00 [显示全部帖子]

 

 

转换出错


图片点击可在新窗口打开查看此主题相关图片如下:1.bmp
图片点击可在新窗口打开查看

代码如下

 

 

Bitmap myBitmap = new Bitmap("Spiral.png")
Rectangle expansionRectangle = new Rectangle(135, 10,   myBitmap.Width, myBitmap.Height)
Rectangle compressionRectangle = new Rectangle(300, 10,   myBitmap.Width / 2, myBitmap.Height / 2)
myGraphics.DrawImage(myBitmap, 10, 10)
myGraphics.DrawImage(myBitmap, expansionRectangle)
myGraphics.DrawImage(myBitmap, compressionRectangle)

     static int ComputePixel(float x, float y, out float x1, out float y1)
        {
           Double r, n
            If (x == 0 && y == 0)
           {
                x1 = x;
                y1 = y;              
                Return 1;  
         }  
         nn = Math.Sqrt(x * x + y * y);
         r = (Math.Abs(x) > Math.Abs(y)) ? Math.Abs(nn / x) : Math.Abs(nn / y);    
         x1 = (float)(r * x);  
         y1 = (float)(r * y); 
          Return 1;    
   }
       static Color GetPixelColorInterpolated(ref Bitmap image, float x, float y)    

   {
           int xi = (int)(x);
            If (x < 0) xi--; 
          int yi = (int)(y);
           If (y < 0) yi--; 
          If (xi < -1 || xi >= image.Width || yi < -1 || yi >= image.Height)
           {                Return GetPixelColorWithOverflow(ref image, -999, -999);
           }
           //get four neighbouring pixels
           If ((xi + 1) < image.Width && xi >= 0 && (yi + 1) < image.Height && yi >= 0)
           {                ushort wt1 = (ushort)((x - xi) * 256.0f), wt2 = (ushort)((y - yi) * 256.0f);
               ushort wd = (ushort)(wt1 * wt2 >> 8);
                ushort wb = (ushort)(wt1 - wd); 
              ushort wc = (ushort)(wt2 - wd); 
              ushort wa = (ushort)(256 - wt1 - wc);
               ushort wrr, wgg, wbb;
               Color clr = image.GetPixel(xi, yi);
               wbb = (ushort)(wa * clr.B); wgg = (ushort)(wa * clr.G); wrr = (ushort)(wa * clr.R);
               clr = image.GetPixel(xi + 1, yi);
               wbb += (ushort)(wb * clr.B); wgg += (ushort)(wb * clr.G); wrr += (ushort)(wb * clr.R); 
               clr = image.GetPixel(xi, yi + 1);        
               wbb += (ushort)(wc * clr.B); wgg += (ushort)(wc * clr.G); wrr += (ushort)(wc * clr.R); 
               clr = image.GetPixel(xi + 1, yi + 1);
               wbb += (ushort)(wd * clr.B); wgg += (ushort)(wd * clr.G); wrr += (ushort)(wd * clr.R);  
             Return Color.FromArgb(255, wrr >> 8, wgg >> 8, wbb >> 8);
           }
           Else  
         {                float t1 = x - xi, t2 = y - yi; 
              float d = t1 * t2;
               float b = t1 - d;
               float c = t2 - d;
               float a = 1 - t1 - c; 
              Color rgb11, rgb21, rgb12, rgb22; 
              rgb11 = GetPixelColorWithOverflow(ref image, xi, yi);
               rgb21 = GetPixelColorWithOverflow(ref image, xi + 1, yi);
                rgb12 = GetPixelColorWithOverflow(ref image, xi, yi + 1);
                rgb22 = GetPixelColorWithOverflow(ref image, xi + 1, yi + 1);
                //calculate linear interpolation
               Return Color.FromArgb(255,
                    (Byte)(a * rgb11.R + b * rgb21.R + c * rgb12.R + d * rgb22.R),
                   (Byte)(a * rgb11.G + b * rgb21.G + c * rgb12.G + d * rgb22.G),
                   (Byte)(a * rgb11.B + b * rgb21.B + c * rgb12.B + d * rgb22.B));
            }
       } 
      static Color GetPixelColorWithOverflow(ref Bitmap image, Long x, Long y)
       {
           If (!IsInside(ref image, x, y)) 
          {
               Return Color.FromArgb(255, 255, 255, 255);
            }
           Return image.GetPixel((int)x, (int)y);   
    } 
      static bool IsInside(ref Bitmap image, Long x, Long y)
       {
           Return (0 <= y && y < image.Height && 0 <= x && x < image.Width); 
      }
       private void transformEllipseToolStripMenuItem_Click(object sender, EventArgs e)
       { 
          Bitmap image = new Bitmap("D:\\PSD\\info1.jpg");
          int x, y;
          float x1, y1;
          float fx, fy, xmid, ymid, ar; 
          Bitmap image2 = new Bitmap(image); 
          xmid = (float)(image.Width / 2.0); 

          ymid = (float)(image.Height / 2.0);
          ar = (float)(image.Height) / (float)(image.Width);
          For (y = 0; y < image.Height; y++) 
          { 
              For (x = 0; x < image.Width; x++)
               { 
                  ComputePixel(ar * (x - xmid), y - ymid, out fx, out fy);
                    x1 = xmid + fx / ar;
                    y1 = ymid + fy;
                   image2.SetPixel(x, y, GetPixelColorInterpolated(ref image, x1, y1)); 
              }
           }
            this.pictureBox1.Image = image2;
        }


 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/3/26 17:24:00 [显示全部帖子]

c语言没学

当时只学习过Fortran语言和DbaseIII,其他语言为学过

 

我可以去研究下

谢谢


 回到顶部