本文整理汇总了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;
}
示例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;
}
示例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;
}