Пример #1
0
        public void ToBitmap(System.Drawing.Bitmap bmp)
        {
            var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            unsafe
            {
                byte *firstPixel = (byte *)data.Scan0;
                var   width      = bmp.Width;
                var   height     = bmp.Height;

                for (var y = 0; y < height; ++y)
                {
                    RGBColor *pixel = (RGBColor *)(firstPixel + y * data.Stride);

                    int pos = y * width;

                    fixed(RGBColor *first = &m_components[pos])
                    fixed(RGBColor * last = &m_components[pos + width - 1])
                    {
                        for (RGBColor *color = first; color <= last; color++)
                        {
                            *pixel = *color;
                            pixel->a = 255;
                            pixel++;
                        }
                    }
                }
            }

            bmp.UnlockBits(data);
        }
Пример #2
0
        public void CopyPixel(int destX, int destY, int srcX, int srcY, RenderBitmap src, float lightAmt)
        {
            int srcIndex = (srcY * src.m_width + srcX);

            unsafe
            {
                RGBColor *rgbColor = (RGBColor *)((byte *)(m_data.Scan0 + m_data.Stride * destY + destX * 4));
                fixed(RGBColor *color = &src.m_components[srcIndex])
                {
                    rgbColor->r = (byte)(color->r * lightAmt);
                    rgbColor->g = (byte)(color->g * lightAmt);
                    rgbColor->b = (byte)(color->b * lightAmt);
                }
            }
        }
Пример #3
0
        public void Clear(byte shade)
        {
            unsafe
            {
                byte *firstPixel = (byte *)m_data.Scan0;
                var   width      = m_bitmap.Width;
                var   height     = m_bitmap.Height;

                int iColor = unchecked ((shade << 24) | (shade << 16) | (shade << 8) | shade);
                int stride = m_data.Stride;

                for (var y = 0; y < height; ++y)
                {
                    RGBColor *first = (RGBColor *)(firstPixel + y * stride);
                    RGBColor *last  = (RGBColor *)(first + width);
                    for (RGBColor *color = first; color <= last; ++color)
                    {
                        *color = *(RGBColor *)&iColor;
                    }
                }
            }
        }