public void SetPixel(int x, int y, PixelData4 val) { int index = m_width * m_bpp * y + x * m_bpp; //BGRA m_imageData[index] = val.B; m_imageData[index + 1] = val.G; m_imageData[index + 2] = val.R; m_imageData[index + 3] = val.A; //alpha m_modify = true; }
public static void BlendColor(ref PixelData4 target, PixelData4 other, float amount) { target.R = (byte)((other.R - (255 - target.R)) * amount + (255 - target.R)); target.G = (byte)((other.G - (255 - target.G)) * amount + (255 - target.G)); target.B = (byte)((other.B - (255 - target.B)) * amount + (255 - target.B)); target.A = (byte)((other.A - (255 - target.A)) * amount + (255 - target.A)); }
public static Bitmap CreateBitmap(int width, int height,PixelData4 col ) { Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat); unsafe { byte* pSrc = (byte*)data.Scan0.ToPointer(); int offset = data.Stride - bitmap.Width * 4; for (int y = 0; y < bitmap.Height; ++y) { for (int x = 0; x < bitmap.Width; ++x) { *(pSrc ) = col.R; *(pSrc + 1) = col.G; *(pSrc + 2) = col.B; *(pSrc + 3) = col.A; pSrc += 4; } pSrc += offset; } } bitmap.UnlockBits(data); return bitmap; }
public static void MixColor(ref PixelData4 target, PixelData4 other, float amount) { target.R = (byte)((other.R - target.R) * amount + target.R); target.G = (byte)((other.G - target.G) * amount + target.G); target.B = (byte)((other.B - target.B) * amount + target.B); target.A = (byte)((other.A - target.A) * amount + target.A); }
public static Bitmap RedMixImage(Bitmap srcBmp, Bitmap srBmp2) { Bitmap destBmp = srcBmp.Clone() as Bitmap; BitmapData srcData = srBmp2.LockBits(new Rectangle(0, 0, srBmp2.Width, srBmp2.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); BitmapData destData = destBmp.LockBits(new Rectangle(0, 0, destBmp.Width, destBmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); PixelData4* dest = (PixelData4*)destData.Scan0; PixelData3* src = (PixelData3*)srcData.Scan0; int srcOffset = srcData.Stride / 3 - srBmp2.Width; int destOffset = destData.Stride / 4 - destBmp.Width; for (int y = 0; y < destBmp.Height; ++y) { for (int x = 0; x < destBmp.Width; ++x) { PixelData4 pixel = new PixelData4( (byte)((*dest).R * ((*src).R / 255f)), (byte)((*dest).G * ((*src).G / 255f)), (*src).B, (*dest).A); *(dest++) = pixel; src++; } src += srcOffset; dest += destOffset; } destBmp.UnlockBits(destData); srBmp2.UnlockBits(srcData); return destBmp; }