本文整理匯總了C#中SdlDotNet.Graphics.Surface.GetColors方法的典型用法代碼示例。如果您正苦於以下問題:C# Surface.GetColors方法的具體用法?C# Surface.GetColors怎麽用?C# Surface.GetColors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SdlDotNet.Graphics.Surface
的用法示例。
在下文中一共展示了Surface.GetColors方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Sprite
public Sprite(Surface surface2)
{
this.surface = surface2;
texture = new SurfaceGl(surface, true);
texture.WrapS = WrapOption.Clamp;
texture.WrapT = WrapOption.Clamp;
//texture.MagFilter = MagnificationOption.GL_LINEAR;
//texture.MinFilter = MinifyingOption.GL_LINEAR_MIPMAP_LINEAR;
int blank = surface.TransparentColor.ToArgb();
bool[,] bitmap = new bool[surface.Width, surface.Height];
Color[,] pixels = surface.GetColors(new System.Drawing.Rectangle(0, 0, surface.Width, surface.Height));
for (int x = 0; x < bitmap.GetLength(0); ++x)
{
for (int y = 0; y < bitmap.GetLength(1); ++y)
{
bitmap[x, y] = !(pixels[x, y].A == 0 || pixels[x, y].ToArgb() == blank);
}
}
vertexes = VertexHelper.CreateRangeFromBitmap(bitmap);
Console.WriteLine("Before {0}", GetCount);
vertexes = VertexHelper.ReduceRange(vertexes, 1);
vertexes = VertexHelper.ReduceRange(vertexes, 2);
vertexes = VertexHelper.ReduceRange(vertexes, 3);
Console.WriteLine("After {0}", GetCount);
vertexes = VertexHelper.SubdivideRange(vertexes, 10);
Console.WriteLine("Subdivide {0}", GetCount);
offset = VertexHelper.GetCentroidOfRange(vertexes);
vertexes = VertexHelper.CenterVertexesRange(vertexes);
}
示例2: SurfaceBitmap
public SurfaceBitmap(Surface surface, Predicate<Color> isOpaque)
{
bitmap = new bool[surface.Width, surface.Height];
Color[,] pixels = surface.GetColors(new System.Drawing.Rectangle(0, 0, surface.Width, surface.Height));
for (int x = 0; x < bitmap.GetLength(0); ++x)
{
for (int y = 0; y < bitmap.GetLength(1); ++y)
{
bitmap[x, y] = isOpaque(pixels[x, y]);
}
}
}
示例3: LoadChipData
public static ColorChipData LoadChipData(MapInfo info)
{
ColorChipData c = new ColorChipData();
c._chipWidth = info.ChipDataInfo.Size.Width;
c._chipHeight = info.ChipDataInfo.Size.Height;
if (info.ChipDataInfo == null || info.ChipDataInfo.ChipInfos.Count == 0)
{
c._colors = new Color[] { Color.White, Color.Black };
c._hardness = new int[] { 0, 1 };
}
else
{
c._colors = new Color[info.ChipDataInfo.ChipInfos.Count];
c._hardness = new int[info.ChipDataInfo.ChipInfos.Count];
List<Color> defaultColors = new List<Color>();
if (info.ChipDataInfo.ChipInfos.Exists((ci) => { return !ci.Color.HasValue; }))
{
string mappingPath = System.IO.Path.Combine(info.DirectoryPath, info.Mapping);
#region マッピングデータを読み込む
if (!string.IsNullOrEmpty(info.Mapping) && System.IO.File.Exists(mappingPath))
{
using (Bitmap mappingBmp = (Bitmap)Bitmap.FromFile(mappingPath))
{
using (Surface ms = new Surface(mappingBmp))
{
Color[,] tmp = ms.GetColors(new Rectangle(0, 0, ms.Width, ms.Height));
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color dc = tmp[i, j];
defaultColors.Add(dc);
}
}
}
}
}
#endregion
}
int idx = 0;
foreach (ChipInfo ci in info.ChipDataInfo.ChipInfos)
{
c._colors[idx] = ci.Color.HasValue ? ci.Color.Value :
(defaultColors.Count > idx ? defaultColors[idx] : Color.Blue);
c._hardness[idx] = ci.Hardness;
idx++;
}
}
return c;
}
示例4: LoadSurfacesFromFile
public static SurfaceCollection LoadSurfacesFromFile(string filePath, Size tileSize)
{
SurfaceCollection ret = new SurfaceCollection();
ret.AlphaBlending = true;
if (!File.Exists(filePath)) return ret;
using (Bitmap bmp = (Bitmap)Bitmap.FromFile(filePath))
{
using (Surface s = new Surface(bmp))
{
s.Lock();
for (int i = 0; i < s.Width; i += tileSize.Width)
{
for (int j = 0; j < s.Height; j += tileSize.Height)
{
Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
ss.Transparent = true;
ss.AlphaBlending = true;
Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
ss.Lock();
ss.SetPixels(Point.Empty, tmp);
tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
ss.Unlock();
ss.Update();
ret.Add(ss);
}
}
s.Unlock();
}
}
return ret;
}
示例5: LoadSurfaces
public static SurfaceCollection LoadSurfaces(string resourceName, Size tileSize)
{
SurfaceCollection ret = new SurfaceCollection();
ret.AlphaBlending = true;
using (Surface s = LoadSurface(resourceName))
{
for (int i = 0; i < s.Width; i += tileSize.Width)
{
for (int j = 0; j < s.Height; j += tileSize.Height)
{
Surface ss = new Surface(tileSize.Width, tileSize.Height, 32, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
ss.Transparent = true;
ss.AlphaBlending = true;
Color[,] tmp = s.GetColors(new Rectangle(i, j, tileSize.Width, tileSize.Height));
ss.SetPixels(Point.Empty, tmp);
tmp = ss.GetColors(new Rectangle(0, 0, ss.Width, ss.Height));
ss.Update();
ret.Add(ss);
}
}
}
return ret;
}
示例6: SetAlpha
public static void SetAlpha(Surface s, float a)
{
if (s == null) return;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Lock();
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
Color c = colors[i, j];
int na = (int)(c.A * a);
colors[i, j] = Color.FromArgb(na < 0 ? 0 : (na > 255 ? 255 : na), c.R, c.G, c.B);
}
}
s.SetPixels(Point.Empty, colors);
s.Unlock();
s.Update();
}
示例7: SetColor
public static void SetColor(Surface s, Color c)
{
if (s == null) return;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Lock();
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
colors[i, j] = Color.FromArgb(colors[i, j].A, c.R, c.G, c.B);
}
}
s.SetPixels(Point.Empty, colors);
s.Unlock();
s.Update();
}
示例8: CreateColored
public static Surface CreateColored(Surface s, Color c0, Color c1)
{
if (s == null) return null;
Color[,] colors = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
for (int i = 0; i < colors.GetLength(0); i++)
{
for (int j = 0; j < colors.GetLength(1); j++)
{
Color c = colors[i, j];
float br = (c.R / 255.0f + c.G / 255.0f + c.B / 255.0f) / 3.0f;
if (br > 0.8f)
{
br = 1.0f;
}
else if (br < 0.2f)
{
br = 0.0f;
}
int r = (int)((1 - br) * c0.R + br * c1.R);
int g = (int)((1 - br) * c0.G + br * c1.G);
int b = (int)((1 - br) * c0.B + br * c1.B);
r = r < 0 ? 0 : (r > 255 ? 255 : r);
g = g < 0 ? 0 : (g > 255 ? 255 : g);
b = b < 0 ? 0 : (b > 255 ? 255 : b);
colors[i, j] = Color.FromArgb(c.A, r, g, b);
Color nc = Color.FromArgb(c.A, r, g, b);
}
}
Surface ns = new Surface(s.Width, s.Height, s.BitsPerPixel, s.RedMask, s.GreenMask, s.BlueMask, s.AlphaMask);
ns.AlphaBlending = s.AlphaBlending;
ns.Alpha = s.Alpha;
ns.Transparent = s.Transparent;
ns.TransparentColor = s.TransparentColor;
ns.Lock();
ns.SetPixels(Point.Empty, colors);
ns.Unlock();
ns.Update();
return ns;
}
示例9: GetAvgColor
public static Color GetAvgColor(Surface s)
{
s.Lock();
Color[,] tmp = s.GetColors(new Rectangle(0, 0, s.Width, s.Height));
s.Unlock();
int num = 0;
double a = 0; double r = 0; double g = 0; double b = 0;
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color pc = tmp[i, j];
if (pc.A != 0)
{
a += pc.A; r += pc.R; g += pc.G; b += pc.B;
num++;
}
}
}
if (num == 0) return Color.Transparent;
a /= (double)num; r /= (double)num; g /= (double)num; b /= (double)num;
int ia = (int)a; int ir = (int)r; int ig = (int)g; int ib = (int)b;
ia = ia < 0 ? 0 : (ia > 255 ? 255 : ia);
ir = ir < 0 ? 0 : (ir > 255 ? 255 : ir);
ig = ig < 0 ? 0 : (ig > 255 ? 255 : ig);
ib = ib < 0 ? 0 : (ib > 255 ? 255 : ib);
return Color.FromArgb(ia, ir, ig, ib);
}
示例10: LoadMapImage
public void LoadMapImage(Bitmap mapBmp, Bitmap chipMapping = null)
{
_chips = new List<uint[]>();
Dictionary<Color, uint> mapping = null;
if (chipMapping != null)
{
mapping = new Dictionary<Color, uint>();
using (Surface ms = new Surface(chipMapping))
{
Color[,] tmp = ms.GetColors(new Rectangle(0, 0, ms.Width, ms.Height));
for (int i = 0; i < tmp.GetLength(0); i++)
{
for (int j = 0; j < tmp.GetLength(1); j++)
{
Color c = tmp[i, j];
uint idx = (uint)(i + j * tmp.GetLength(0));
if (mapping.ContainsKey(c)) mapping[c] = idx;
else mapping.Add(c, idx);
}
}
}
}
Color[,] colors;
using (Surface s = new Surface(mapBmp))
{
colors = s.GetColors(new Rectangle(0, 0, mapBmp.Width, mapBmp.Height));
}
_columnNum = colors.GetLength(0);
_rowNum = colors.GetLength(1);
if (colors == null)
{
#warning 例外
}
else if (mapping != null)
{
for (int i = 0; i < _columnNum; i++)
{
uint[] column = new uint[_rowNum];
for (int j = 0; j < _rowNum; j++)
{
Color c = colors[i, j];
if (mapping.ContainsKey(c))
column[j] = mapping[c];
else
column[j] = 0;
}
_chips.Add(column);
}
}
else
{
for (int i = 0; i < _columnNum; i++)
{
uint[] column = new uint[_rowNum];
for (int j = 0; j < _rowNum; j++)
{
Color c = colors[i, j];
if ((c.ToArgb() & 0x00ffffff) == 0x00ffffff) column[j] = 0;
else column[j] = 1;
}
_chips.Add(column);
}
}
}