本文整理汇总了C#中OxyPlot.OxyColor.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# OxyColor.GetLength方法的具体用法?C# OxyColor.GetLength怎么用?C# OxyColor.GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OxyPlot.OxyColor
的用法示例。
在下文中一共展示了OxyColor.GetLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encode
/// <summary>
/// Encodes the specified image data to png.
/// </summary>
/// <param name="pixels">
/// The pixel data (bottom line first).
/// </param>
/// <param name="dpi">
/// The image resolution in dots per inch.
/// </param>
/// <returns>
/// The png image data.
/// </returns>
public static byte[] Encode(OxyColor[,] pixels, int dpi = 96)
{
int height = pixels.GetLength(0);
int width = pixels.GetLength(1);
var bytes = new byte[(width * height * 4) + height];
int k = 0;
for (int i = height - 1; i >= 0; i--)
{
bytes[k++] = 0; // Filter
for (int j = 0; j < width; j++)
{
bytes[k++] = pixels[i, j].R;
bytes[k++] = pixels[i, j].G;
bytes[k++] = pixels[i, j].B;
bytes[k++] = pixels[i, j].A;
}
}
var w = new MemoryWriter();
w.Write((byte)0x89);
w.Write("PNG\r\n\x1a\n".ToCharArray());
WriteChunk(w, "IHDR", CreateHeaderData(width, height));
WriteChunk(w, "pHYs", CreatePhysicalDimensionsData(dpi, dpi));
WriteChunk(w, "IDAT", CreateUncompressedBlocks(bytes));
WriteChunk(w, "IEND", new byte[0]);
return w.ToArray();
}
示例2: Encode
/// <summary>
/// Encodes the specified image data to png.
/// </summary>
/// <param name="pixels">The pixel data (bottom line first).</param>
/// <returns>The png image data.</returns>
public byte[] Encode(OxyColor[,] pixels)
{
int width = pixels.GetLength(0);
int height = pixels.GetLength(1);
var bytes = new byte[width * height * 4];
int k = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
bytes[k++] = pixels[x, y].B;
bytes[k++] = pixels[x, y].G;
bytes[k++] = pixels[x, y].R;
bytes[k++] = pixels[x, y].A;
}
}
var ms = new MemoryStream();
var w = new BinaryWriter(ms);
const int OffBits = 14 + 40;
var size = OffBits + bytes.Length;
// Bitmap file header (14 bytes)
w.Write((byte)'B');
w.Write((byte)'M');
w.Write((uint)size);
w.Write((ushort)0);
w.Write((ushort)0);
w.Write((uint)OffBits);
// Bitmap info header (40 bytes)
WriteBitmapInfoHeader(w, width, height, 32, bytes.Length, this.options.DpiX, this.options.DpiY);
// Bitmap info V4 header (108 bytes)
//// WriteBitmapV4Header(w, width, height, 32, bytes.Length, this.options.DpiX, this.options.DpiY);
// Pixel array (from bottom-left corner)
w.Write(bytes);
return ms.ToArray();
}
示例3: FromArgbX
/// <summary>
/// Creates an <see cref="OxyImage"/> from the specified <see cref="OxyColor"/> array.
/// </summary>
/// <param name="data">
/// The pixel data, indexed as [row,column] (from bottom-left).
/// </param>
/// <param name="dpi">
/// The resolution.
/// </param>
/// <returns>
/// An <see cref="OxyImage"/>.
/// </returns>
/// <remarks>
/// This method is creating a simple BitmapInfoHeader.
/// </remarks>
public static OxyImage FromArgbX(OxyColor[,] data, int dpi = 96)
{
int height = data.GetLength(0);
int width = data.GetLength(1);
var bytes = new byte[width * height * 4];
int k = 0;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
bytes[k++] = data[i, j].B;
bytes[k++] = data[i, j].G;
bytes[k++] = data[i, j].R;
bytes[k++] = data[i, j].A;
}
}
return FromArgbX(width, height, bytes, dpi);
}
示例4: Encode
/// <summary>
/// Encodes the specified image data to png.
/// </summary>
/// <param name="pixels">The pixel data indexed as [x,y] (bottom line first).</param>
/// <returns>The png image data.</returns>
public byte[] Encode(OxyColor[,] pixels)
{
int width = pixels.GetLength(0);
int height = pixels.GetLength(1);
var bytes = new byte[(width * height * 4) + height];
int k = 0;
for (int y = 0; y < height; y++)
{
bytes[k++] = 0; // Filter
for (int x = 0; x < width; x++)
{
bytes[k++] = pixels[x, y].R;
bytes[k++] = pixels[x, y].G;
bytes[k++] = pixels[x, y].B;
bytes[k++] = pixels[x, y].A;
}
}
var w = new MemoryWriter();
w.Write((byte)0x89);
w.Write("PNG\r\n\x1a\n".ToCharArray());
WriteChunk(w, "IHDR", CreateHeaderData(width, height));
WriteChunk(w, "pHYs", CreatePhysicalDimensionsData(this.options.DpiX, this.options.DpiY));
WriteChunk(w, "IDAT", CreateUncompressedBlocks(bytes));
WriteChunk(w, "IEND", new byte[0]);
return w.ToArray();
}