當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.Flip方法代碼示例

本文整理匯總了C#中Bitmap.Flip方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.Flip方法的具體用法?C# Bitmap.Flip怎麽用?C# Bitmap.Flip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bitmap的用法示例。


在下文中一共展示了Bitmap.Flip方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Skew_V

 static Bitmap Skew_V(Bitmap bmp, double angle)
 {
     angle = (angle % (2.0 * Math.PI) + 2.0 * Math.PI) % (2.0 * Math.PI);
     if (angle >= 0.5 * Math.PI && angle < 1.5 * Math.PI)
     {
         bmp.Flip(true);
         angle += angle >= Math.PI ? -Math.PI : Math.PI;
     }
     double sin = Math.Sin(angle), cos = Math.Cos(angle), tan = sin / cos;
     double W = bmp.Width, H = bmp.Height;
     if ((W * cos).Round() == 0) return null;
     Bitmap ans; BITMAP.New(out ans, (W * cos).Round(), (H + Math.Abs(W * sin)).Round());
     BitmapData data_bmp = bmp.GetBitmapData();
     BitmapData data_ans = ans.GetBitmapData();
     byte* ptr_bmp = data_bmp.GetPointer();
     byte* ptr_ans = data_ans.GetPointer();
     double hs = angle >= 0 && angle < Math.PI ? 0 : Math.Abs(W * sin);
     Parallel.For(0, data_ans.Height, h =>
     {
         int i1 = data_ans.Stride * h;
         int i2;
         for (int w = 0; w < data_ans.Width; w++)
         {
             int y = (h - hs - w * tan).Round();
             int x = (Math.Abs(w / cos)).Round();
             if (y < 0 || y >= data_bmp.Width) { i1 += 3; ptr_ans[i1++] = 0; continue; }
             i2 = y * data_bmp.Stride + 4 * x;
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
         }
     });
     for (int h = 0; h < ans.Height; h++)
     {
         for (int w = 0; w < ans.Width; w++, ptr_ans += 4)
         {
             int y = (h - hs - w * tan).Round();
             int x = (Math.Abs(w / cos)).Round();
             if (y < 0 || y >= bmp.Width) { ptr_ans[3] = 0; continue; }
             int i = y * data_bmp.Stride + 4 * x;
             ptr_ans[0] = ptr_bmp[i + 0];
             ptr_ans[1] = ptr_bmp[i + 1];
             ptr_ans[2] = ptr_bmp[i + 2];
             ptr_ans[3] = ptr_bmp[i + 3];
         }
         ptr_ans += data_ans.Stride - 4 * ans.Width;
     }
     bmp.UnlockBits(data_bmp);
     ans.UnlockBits(data_ans);
     return ans;
 }
開發者ID:fsps60312,項目名稱:Digging-Game-2,代碼行數:52,代碼來源:BITMAP.cs

示例2: Translate_V

 static Bitmap Translate_V(Bitmap bmp, double angle)
 {
     angle = (angle % (2.0 * Math.PI) + 2.0 * Math.PI) % (2.0 * Math.PI);
     if (angle >= 0.5 * Math.PI && angle < 1.5 * Math.PI)
     {
         bmp.Flip(true);
         angle += angle >= Math.PI ? -Math.PI : Math.PI;
     }
     int limit = 1000000;
     if (Math.Min(Math.Abs(angle - 0.5 * Math.PI), Math.Abs(angle - 1.5 * Math.PI)) <= 0.5 * Math.PI - Math.Abs(Math.Atan(limit))) return null;
     double sin = Math.Sin(angle), cos = Math.Cos(angle), tan = sin / cos;
     double W = bmp.Width, H = bmp.Height;
     Bitmap ans; BITMAP.New(out ans,(int)W, (H + Math.Abs(W * tan)).Round());
     BitmapData data_bmp = bmp.GetBitmapData();
     BitmapData data_ans = ans.GetBitmapData();
     byte* ptr_bmp = data_bmp.GetPointer();
     byte* ptr_ans = data_ans.GetPointer();
     double hs = angle >= 0 && angle < Math.PI ? 0 : Math.Abs(W * tan);
     Parallel.For(0, data_ans.Height, h =>
     {
         int i1 = data_ans.Stride * h;
         int i2;
         for (int w = 0; w < data_ans.Width; w++)
         {
             int y = (h - hs - w * tan).Round();
             if (y < 0 || y >= bmp.Height) { i1 += 3; ptr_ans[i1++] = 0; continue; }
             i2 = y * data_bmp.Stride + 4 * w;
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
         }
     });
     bmp.UnlockBits(data_bmp);
     ans.UnlockBits(data_ans);
     return ans;
 }
開發者ID:fsps60312,項目名稱:Digging-Game-2,代碼行數:37,代碼來源:BITMAP.cs

示例3: Skew_H

 static Bitmap Skew_H(Bitmap bmp, double angle)
 {
     angle = (angle % (2.0 * Math.PI) + 2.0 * Math.PI) % (2.0 * Math.PI);
     if (angle >= 0.5 * Math.PI && angle < 1.5 * Math.PI)
     {
         bmp.Flip(false);
         angle += angle >= Math.PI ? -Math.PI : Math.PI;
     }
     double sin = Math.Sin(angle), cos = Math.Cos(angle), tan = sin / cos;
     double W = bmp.Width, H = bmp.Height;
     if ((H * cos).Round() == 0) return null;
     Bitmap ans; BITMAP.New(out ans, (W + Math.Abs(H * sin)).Round(), (H * cos).Round());
     BitmapData data_bmp = bmp.GetBitmapData();
     BitmapData data_ans = ans.GetBitmapData();
     byte* ptr_bmp = data_bmp.GetPointer();
     byte* ptr_ans = data_ans.GetPointer();
     double ws = angle >= 0 && angle < Math.PI ? Math.Abs(H * sin) : 0;
     Parallel.For(0, data_ans.Height, h =>
     {
         int i1 = data_ans.Stride * h;
         int i2;
         for (int w = 0; w < data_ans.Width; w++)
         {
             int x = (w - ws + h * tan).Round();
             int y = (Math.Abs(h / cos)).Round();
             if (x < 0 || x >= data_bmp.Width) { i1 += 3; ptr_ans[i1++] = 0; continue; }
             i2 = y * data_bmp.Stride + 4 * x;
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
             ptr_ans[i1++] = ptr_bmp[i2++];
         }
     });
     bmp.UnlockBits(data_bmp);
     ans.UnlockBits(data_ans);
     return ans;
 }
開發者ID:fsps60312,項目名稱:Digging-Game-2,代碼行數:37,代碼來源:BITMAP.cs


注:本文中的Bitmap.Flip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。