本文整理汇总了C#中Bitmap.GetBitmapData方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetBitmapData方法的具体用法?C# Bitmap.GetBitmapData怎么用?C# Bitmap.GetBitmapData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetBitmapData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImage
protected override void GetImage(out Bitmap bac)
{
bac = IMAGE;
if (bac.Size != GetSize()) bac = bac.Resize(RECT.Size);
BitmapData data_bac = bac.GetBitmapData();
DrawLOCKED(data_bac);
bac.UnlockBits(data_bac);
}
示例2: GetImage
static Bitmap GetImage(out Bitmap bac)
{
bac = new Bitmap(IMAGE);
BitmapData data_bac = bac.GetBitmapData();
PointD center = bac.Half();
double angle = VALUE * 0.004 * Math.PI;
PointD vector = new PointD(Math.Sin(angle), -Math.Cos(angle));
Bitmap bmp = SHORT_NEEDLE.Rotate(angle);
data_bac.Paste(bmp, center.Add(vector, 0.5 * SHORT_NEEDLE.Height) - bmp.Half(), ImagePasteMode.Transparent);
angle = VALUE * 0.04 * Math.PI;
vector = new PointD(Math.Sin(angle), -Math.Cos(angle));
bmp = LONG_NEEDLE.Rotate(angle);
data_bac.Paste(bmp, center.Add(vector, 0.5 * LONG_NEEDLE.Height) - bmp.Half(), ImagePasteMode.Transparent);
bac.UnlockBits(data_bac);
return bac;
}
示例3: Get_PANEL_Image
protected virtual void Get_PANEL_Image(out Bitmap bac)
{
bac = new Bitmap(PANEL);
BitmapData data_bac=bac.GetBitmapData();
Draw_PANEL_Image(data_bac);
bac.UnlockBits(data_bac);
}
示例4: Station
protected Station(string data)
{
StationEntered += Gas_Station_Type_StationEntered;
DATA = data.Split("\r\n");
string settingfile_location = DATA[0];
if (DATA[1] != "[Labels]") throw new FormatException();
string[] labels = new string[] { "Station Location", "Exterior", "Panel", "Load Images", "Images On Panel", "Buttons" };
int n = int.Parse(DATA[2]);
//if (n != labels.Length) throw new FormatException();
for (int i = 0; i < labels.Length; i++)
{
if (!STRING.IndexOf(DATA, labels[i]).AtRange(3, 2 + n)) throw new FormatException();
}
int lab_idx = 0;
int idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
LOCATION = int.Parse(DATA[idx + 1]);
}
idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
EXTERIOR = BITMAP.FromFile(settingfile_location + DATA[++idx]);
}
idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
PANEL = BITMAP.FromFile(settingfile_location + DATA[++idx]);
}
idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
n = int.Parse(DATA[++idx]);
for (int i = 0; i < n; i++)
{
Bitmap bmp = BITMAP.FromFile(settingfile_location + DATA[++idx]);
IMAGES.Add(DATA[++idx], bmp);
}
}
idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
n = int.Parse(DATA[++idx]);
BitmapData data_bac = PANEL.GetBitmapData();
for (int i = 0; i < n; i++)
{
string s = DATA[++idx];
Point p = POINT.Parse(DATA[++idx]);
Merge_Images(data_bac, s, p);
}
PANEL.UnlockBits(data_bac);
}
idx = STRING.IndexOf(DATA, "[" + labels[lab_idx++] + "]");
{
n = int.Parse(DATA[++idx]);
for (int i = 0; i < n; i++)
{
string s = DATA[++idx];
s = s.Replace(@"\r\n", "\r\n");
Point p = POINT.Parse(DATA[++idx]);
Size sz = new Size(POINT.Parse(DATA[++idx]));
CONTROLS.Add(s, new MyButton(s, this, new Rectangle(p, sz), Color.FromArgb(255, 0, 0)));
}
}
}
示例5: JoinRight
static Bitmap JoinRight(this Bitmap bac, Bitmap bmp, int dis, ref PointD center)
{
if (bmp == null) return bac;
int h1 = Math.Min(0, dis), h2 = Math.Max(bac.Height, dis + bmp.Height);
if (center != null) center += new PointD(0.0, (double)-h1);
Bitmap ans; BITMAP.New(out ans,bac.Width + bmp.Width, h2 - h1);
BitmapData data_ans = ans.GetBitmapData();
BitmapData data_bmp = bmp.GetBitmapData();
BitmapData data_bac = bac.GetBitmapData();
byte* ptr_ans = data_ans.GetPointer();
byte* ptr_bmp = data_bmp.GetPointer();
byte* ptr_bac = data_bac.GetPointer();
int gap = Math.Max(0, -dis);
ptr_ans += data_ans.Stride * gap;
for (int w = 0; w < bac.Width; w++)
{
for (int h = 0; h < bac.Height; h++, ptr_ans += data_ans.Stride, ptr_bac += data_bac.Stride)
{
ptr_ans[0] = ptr_bac[0];
ptr_ans[1] = ptr_bac[1];
ptr_ans[2] = ptr_bac[2];
ptr_ans[3] = ptr_bac[3];
}
ptr_ans += 4 - data_ans.Stride * bac.Height;
ptr_bac += 4 - data_bac.Stride * bac.Height;
}
ptr_ans -= data_ans.Stride * gap;
ptr_ans += data_ans.Stride * Math.Max(0, dis);
for (int w = 0; w < bmp.Width; w++)
{
for (int h = 0; h < bmp.Height; h++, ptr_ans += data_ans.Stride, ptr_bmp += data_bmp.Stride)
{
ptr_ans[0] = ptr_bmp[0];
ptr_ans[1] = ptr_bmp[1];
ptr_ans[2] = ptr_bmp[2];
ptr_ans[3] = ptr_bmp[3];
}
ptr_ans += 4 - data_ans.Stride * bmp.Height;
ptr_bmp += 4 - data_bmp.Stride * bmp.Height;
}
bac.UnlockBits(data_bac);
bmp.UnlockBits(data_bmp);
ans.UnlockBits(data_ans);
return ans;
}
示例6: Paste
public static Bitmap Paste(this Bitmap bac, Bitmap bmp, Point p, ImagePasteMode imagepastemode, Rectangle region = default(Rectangle))
{
int w1 = Math.Max(-p.X, 0), w2 = Math.Min(bmp.Width, bac.Width - p.X);
int h1 = Math.Max(-p.Y, 0), h2 = Math.Min(bmp.Height, bac.Height - p.Y);
if (w1 >= w2 || h1 >= h2) return bac;
Point sp = new Point(w1 + p.X, h1 + p.Y);
BitmapData data_bac = bac.GetBitmapData(new Rectangle(sp, new Size(w2 - w1, h2 - h1)));
BitmapData data_bmp = bmp.GetBitmapData(new Rectangle(new Point(w1, h1), new Size(w2 - w1, h2 - h1)));
if (region != default(Rectangle)) region = region.Add_Location(-sp.X, -sp.Y);
data_bac.Paste(data_bmp, new Point(0, 0), imagepastemode, region);
bac.UnlockBits(data_bac);
bmp.UnlockBits(data_bmp);
return bac;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: Resize_H
static Bitmap Resize_H(Bitmap bmp, int height)
{
if (height == 0) return null;
bool nega = height < 0;
if (nega) height *= -1;
Bitmap ans; BITMAP.New(out ans,bmp.Width, height);
BitmapData data_bmp = bmp.GetBitmapData();
BitmapData data_ans = ans.GetBitmapData();
byte* ptr_bmp = data_bmp.GetPointer();
byte* ptr_ans = data_ans.GetPointer();
double ratio = (double)(bmp.Height - 1) / (height - 1);
Parallel.For(0, data_ans.Height, h =>
{
int i1 = data_ans.Stride * h;
int i2 = data_bmp.Stride * (h * ratio).Round();
for (int w = 0; w < data_ans.Width; 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++];
}
});
if (nega) data_ans.Flip(false);
bmp.UnlockBits(data_bmp);
ans.UnlockBits(data_ans);
return ans;
}
示例11: New
public static void New(out Bitmap ans, int width, int height, object color = null)
{
ans = new Bitmap(width, height, PixelFormat.Format32bppArgb);
if (color == null) return;
Color c = (Color)color;
BitmapData data_ans = ans.GetBitmapData();
byte* ptr_ans = data_ans.GetPointer();
Parallel.For(0, height, h =>
{
int i = data_ans.Stride * h;
for (int w = 0; w < width; w++)
{
ptr_ans[i++] = c.B;
ptr_ans[i++] = c.G;
ptr_ans[i++] = c.R;
ptr_ans[i++] = c.A;
}
});
ans.UnlockBits(data_ans);
}
示例12: DrawOpaque
public static void DrawOpaque(this BitmapData data_bac,Bitmap bmp)
{
BitmapData data_bmp = bmp.GetBitmapData();
DrawOpaque(data_bac, data_bmp);
bmp.UnlockBits(data_bmp);
}
示例13: Resize_W
static Bitmap Resize_W(Bitmap bmp, int width)
{
if (width == 0) return null;
bool nega = width < 0;
if (nega) width *= -1;
Bitmap ans; BITMAP.New(out ans,width, bmp.Height);
BitmapData data_bmp = bmp.GetBitmapData();
BitmapData data_ans = ans.GetBitmapData();
byte* ptr_bmp = data_bmp.GetPointer();
byte* ptr_ans = data_ans.GetPointer();
double ratio = (double)(bmp.Width - 1) / (width - 1);
int stride1 = data_ans.Stride - 4;
int stride2 = data_bmp.Stride - 4;
Parallel.For(0, data_ans.Width, w =>
{
int i1 = 4 * w;
int i2 = 4 * (w * ratio).Round();
for (int h = 0; h < data_ans.Height; h++)
{
ptr_ans[i1++] = ptr_bmp[i2++];
ptr_ans[i1++] = ptr_bmp[i2++];
ptr_ans[i1++] = ptr_bmp[i2++];
ptr_ans[i1++] = ptr_bmp[i2++];
i1 += stride1;
i2 += stride2;
}
});
if (nega) data_ans.Flip(true);
bmp.UnlockBits(data_bmp);
ans.UnlockBits(data_ans);
return ans;
}
示例14: Get_Image
public static void Get_Image(out Bitmap bac)
{
BITMAP.New(out bac,Size);
BitmapData data_bac = bac.GetBitmapData();
DrawBackgroundImage(data_bac);
if (!Pod.PAUSED || !PublicVariables.LOW_PERFORMANCE_MODE)
{
Block.Draw_Image(data_bac);
data_bac.Paste(Pod.GetImage(), WorldToClientD(Pod.POS) - Pod.CENTER,ImagePasteMode.Transparent);
}
foreach (var a in OBJECTS)
{
a.DrawImage(data_bac);
}
Altimeter.DrawImage(data_bac);
GasGauge.Draw_Image(data_bac);
Health.Draw_Image(data_bac);
Money.DrawImage(data_bac);
OreStorage.DrawImage(data_bac);
foreach(var a in PodMessage.MSGS)
{
a.DrawImage(data_bac);
}
foreach(var a in IMPACK_EFFECT)
{
a.DrawImage(data_bac);
}
Station.DrawImageAll(data_bac);
Win8Message.DrawImageAll(data_bac);
if (Math.Cos(LAVA_TIME)!=1.0)
{
double ratio = 0.5 * (-0.5 * Math.Cos(LAVA_TIME) + 0.5);
data_bac.Merge_RGB(Color.FromArgb(255, 255, 0), ratio);
Bitmap bmp = "LAVA".ToBitmap(FONT_FOR_INITIALIZE, Color.FromArgb(255, 255, 255));
data_bac.Paste(bmp.Multiply_A(ratio), data_bac.Half() - bmp.Half(), ImagePasteMode.Gradient);
//bmp.Dispose();
}
if (BLACK_RATIO > 0.0)
{
data_bac.Multiply_RGB(1.0 - BLACK_RATIO);
Bitmap bmp = "PAUSED".ToBitmap(FONT_FOR_INITIALIZE, Color.FromArgb(255, 255, 255));
data_bac.Paste(bmp.Multiply_A(BLACK_RATIO), data_bac.Half() - bmp.Half(), ImagePasteMode.Gradient);
//bmp.Dispose();
}
if(Game.GAME_OVERED!=null&&Game.GAME_OVER_STATE<=0.0)
{
double ratio = 0.5 * Math.Min(Game.GAME_OVER_PERIOD, -Game.GAME_OVER_STATE) / Game.GAME_OVER_PERIOD;
data_bac.Merge_RGB(Color.FromArgb(255,0,0),ratio);
Bitmap bmp = Game.GAME_OVERED.ToBitmap(FONT_FOR_INITIALIZE, Color.FromArgb(255, 255, 255));
data_bac.Paste(bmp.Multiply_A(ratio), data_bac.Half() - bmp.Half(), ImagePasteMode.Gradient);
//bmp.Dispose();
}
bac.UnlockBits(data_bac);
}