2using System.Collections.Generic;
6using System.Threading.Tasks;
29 public Bytemap(
int nChannels,
int nHeight,
int nWidth,
byte[] rgData =
null)
31 int nSize = nChannels * nHeight * nWidth;
32 m_rgData = (rgData !=
null) ? rgData :
new byte[nSize];
33 m_nChannels = nChannels;
36 m_nChannelOffset = nHeight * nWidth;
47 int nWidth = data.
Width;
49 int nSize = nChannels * nHeight * nWidth;
50 m_rgData =
new byte[nSize];
51 m_nChannels = nChannels;
54 m_nChannelOffset = nHeight * nWidth;
56 Array.Copy(data.
Bytes, m_rgData, nSize);
67 int nIdx = nY * m_nWidth + nX;
72 m_rgData[nIdx + m_nChannelOffset] = clr;
73 m_rgData[nIdx + m_nChannelOffset * 2] = clr;
83 public void SetPixel(
int nX,
int nY, Color clr)
85 byte bR = (byte)clr.R;
86 byte bG = (
byte)clr.G;
87 byte bB = (byte)clr.B;
89 int nIdx = nY * m_nWidth + nX;
94 m_rgData[nIdx + m_nChannelOffset] = bG;
95 m_rgData[nIdx + m_nChannelOffset * 2] = bB;
107 int nIdx = nY * m_nWidth + nX;
108 byte bR = m_rgData[nIdx];
112 if (m_nChannels == 3)
114 bG = m_rgData[nIdx + m_nChannelOffset];
115 bB = m_rgData[nIdx + m_nChannelOffset * 2];
118 return Color.FromArgb(bR, bG, bB);
126 Array.Clear(m_rgData, 0, m_rgData.Length);
134 get {
return m_rgData; }
142 get {
return m_nChannels; }
150 get {
return m_nHeight; }
158 get {
return m_nWidth; }
167 Bitmap bmp =
new Bitmap(m_nWidth, m_nHeight);
172 for (
int y = 0; y < m_nHeight; y++)
174 for (
int x = 0; x < m_nWidth; x++)
198 for (
int y = 0; y < bmp.Height; y++)
200 for (
int x = 0; x < bmp.Width; x++)
The Bytemap operates similar to a bitmap but is actually just an array of bytes.
int Channels
Specifies the channels of the data.
int Height
Specifies the height of the data.
Color GetPixel(int nX, int nY)
Get the color of a pixel in the map.
void Clear()
Reset all values to zero.
Bytemap(Bytemap data)
The constructorl
void SetPixel(int nX, int nY, byte clr)
Set a given pixel to a given color.
Bytemap(int nChannels, int nHeight, int nWidth, byte[] rgData=null)
The constructor.
byte[] Bytes
Specifies the data itself.
void SetPixel(int nX, int nY, Color clr)
Set a given pixel to a given color.
static Bytemap FromImage(Bitmap bmp)
Converts a bitmap into a new Bytemap.
Bitmap ToImage()
Converts the Bytemap into a Bitmap.
int Width
Specifies the width of the data.
The LockBitmap class provides very efficient SetPixel and GetPixel functionality of a bitmap by using...
Color GetPixel(int x, int y)
Get the color of the specified pixel
void SetPixel(int x, int y, Color color)
Set the color of the specified pixel
void UnlockBits()
Unlock bitmap data, releasing its underlying data.
void LockBits()
Lock bitmap data to access its underlying raw data.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.