public static Bitmap AddAlpha(Bitmap srcBmp, Bitmap srcAlpha) { DevImage newImage = new DevImage(srcBmp); Bitmap destBmp = newImage.BmpImage.Clone() as Bitmap; BitmapData srcData = srcAlpha.LockBits(new Rectangle(0, 0, srcAlpha.Width, srcAlpha.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); BitmapData destData = destBmp.LockBits(new Rectangle(0, 0, destBmp.Width, destBmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); byte* dest = (byte*)destData.Scan0; byte* src = (byte*)srcData.Scan0; int srcOffset = srcData.Stride - srcAlpha.Width * 4; int destOffset = destData.Stride - destBmp.Width * 4; for (int y = 0; y < destBmp.Height; ++y) { for (int x = 0; x < destBmp.Width; ++x) { *(dest + 3) = *(src); //alpha = red src += 4; dest += 4; } src += srcOffset; dest += destOffset; } destBmp.UnlockBits(destData); srcAlpha.UnlockBits(srcData); return destBmp; }
public ViewDevImage(Int32 nWidth, Int32 nHeight) { m_ImageReSize.Width = nWidth; m_ImageReSize.Height = nHeight; m_dImage = new DevImage(m_ImageReSize.Width, m_ImageReSize.Height); }
public ViewDevImage(Bitmap bmp) { m_dImage = new DevImage(bmp); m_ImageReSize.Width = m_dImage.Width; m_ImageReSize.Height = m_dImage.Height; }
public static DevImage FromBytes(byte[] bytes) { DevImage newImage = new DevImage(1, 1); if (newImage.Load(bytes)) { return newImage; } return null; }
public Main(MainForm form) { m_form = form; m_devImage = new DevImage(100, 100); m_browser = new Browser(); m_linePen.Color = Form.LineColor; InitData(); }
public static double[] GreyscaleHistogram(DevImage img) { double[] histogram = new double[256]; img.LockBitmap(); for (int y = 0; y < img.Width; y++) { for (int x = 0; x < img.Height; x++) { histogram[img.GetGreyPixel(y, x)]++; } } img.UnlockBitmap(); return histogram; }
public static double[] Histogram(DevImage img) { double[] histogram = new double[64]; img.LockBitmap(); for (int y = 0; y < img.Width; y++) { for (int x = 0; x < img.Height; x++) { histogram[Pixel.GetRGBHistogramValue(y, x, img)]++; } } img.UnlockBitmap(); return histogram; }
public static Bitmap LaplaceGreyscale(DevImage img) { Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); img.LockBitmap(); for (int y = 1; y < img.Width - 1; y++) { for (int x = 1; x < img.Height - 1; x++) { int[,] c = Pixel.GetGrey3x3(x, y,img); int val = (((c[0, 0] + c[0, 1] + c[0, 2] + c[1, 0] + c[1, 2] + c[2, 0] + c[2, 1] + c[2, 2]) * -1) + (c[1, 1] * 8)) + 128; if (val >= 128) val = 0; else val = 255; bmp.SetPixel(y, x, Color.FromArgb(val, val, val)); } } img.UnlockBitmap(); return bmp; }
public static Bitmap Laplace(DevImage img) { Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); img.LockBitmap(); for (int y = 1; y < img.Width - 1; y++) { for (int x = 1; x < img.Height - 1; x++) { Color[,] c = Pixel.Get3x3(x, y,img); int red = (((c[0, 0].R + c[0, 1].R + c[0, 2].R + c[1, 0].R + c[1, 2].R + c[2, 0].R + c[2, 1].R + c[2, 2].R) * -1) + (c[1, 1].R * 8)) + 128; int green = (((c[0, 0].G + c[0, 1].G + c[0, 2].G + c[1, 0].G + c[1, 2].G + c[2, 0].G + c[2, 1].G + c[2, 2].G) * -1) + (c[1, 1].G * 8)) + 128; int blue = (((c[0, 0].B + c[0, 1].B + c[0, 2].B + c[1, 0].B + c[1, 2].B + c[2, 0].B + c[2, 1].B + c[2, 2].B) * -1) + (c[1, 1].B * 8)) + 128; if (red >= 128) red = 0; else red = 255; if (green >= 128) green = 0; else green = 255; if (blue >= 128) blue = 0; else blue = 255; bmp.SetPixel(y, x, Color.FromArgb(red, green, blue)); } } img.UnlockBitmap(); return bmp; }
public static DevImage FromFile(string path) { DevImage newImage = new DevImage(1, 1); if (newImage.Load(path)) { return newImage; } return null; }
public bool CopyImg(Int32 offX, Int32 offY, DevImage image) { //* if(image == null) return false; if((image.Width > m_width - offX) && (image.Height > m_height - offY)) return false; LockBitmap(); image.LockBitmap(); byte[] val = new byte[4]; for (int i = 0; i < image.Height; i++) { for (int j = 0; j < image.m_width; j++) { val[0] = image.GetPixel(j, i).A; val[1] = image.GetPixel(j, i).R; val[2] = image.GetPixel(j, i).G; val[3] = image.GetPixel(j, i).B; SetPixel(offX + j, offY + i, val); } } image.UnlockBitmap(); UnlockBitmap(); return true; /**/ //Bitmap bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format24bppRgb); //Graphics g = Graphics.FromImage(bmp); //g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, // GraphicsUnit.Pixel); //g.Dispose(); //return true; }
public static void MergeImageRect(DevImage image, Bitmap srcImage, TPoint point) { BitmapData srcData = srcImage.LockBits(new Rectangle(0, 0, srcImage.Width, srcImage.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); byte* pSrc = (byte*)srcData.Scan0; int offset = srcData.Stride - srcImage.Width * 4; for (int y = 0; y < srcImage.Height; ++y) { for (int x = 0; x < srcImage.Width; ++x) { int index = image.Width * 4 * (y + point.Y) + (x + point.X) * 4; image.ImageData[index++] = *(pSrc+2); image.ImageData[index++] = *(pSrc+1); image.ImageData[index++] = *(pSrc); image.ImageData[index] = *(pSrc+3); pSrc += 4; } pSrc += offset; } srcImage.UnlockBits(srcData); }
public static Bitmap SplitImage(DevImage image, Rectangle rect) { Bitmap destBmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb); image.LockBitmap(); BitmapData destData = destBmp.LockBits(new Rectangle(0, 0, destBmp.Width, destBmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); byte* pDest = (byte*)destData.Scan0; int offset = destData.Stride - destBmp.Width * 4; for (int y = 0; y < destBmp.Height; ++y) { for (int x = 0; x < destBmp.Width; ++x) { Color color = image.GetPixel(x + rect.Left, y + rect.Top); *(pDest++) = color.R; *(pDest++) = color.G; *(pDest++) = color.B; *(pDest++) = color.A; } pDest += offset; } image.UnlockBitmap(); destBmp.UnlockBits(destData); return destBmp; }
internal void Init(Main main) { m_main = main; if (m_dImage == null) { m_dImage = new DevImage(100, 100); } m_regionPen.Color = m_main.Form.LineColor; }
public static Bitmap Median3x3(DevImage img) { Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); img.LockBitmap(); for (int y = 1; y < img.Width - 1; y++) { for (int x = 1; x < img.Height - 1; x++) { Color[,] c = Pixel.Get3x3(x, y,img); int red = Median(c[0, 0].R, c[0, 1].R, c[0, 2].R, c[1, 0].R, c[1, 1].R, c[1, 2].R, c[2, 0].R, c[2, 1].R, c[2, 2].R); int green = Median(c[0, 0].G, c[0, 1].G, c[0, 2].G, c[1, 0].G, c[1, 1].G, c[1, 2].G, c[2, 0].G, c[2, 1].G, c[2, 2].G); int blue = Median(c[0, 0].B, c[0, 1].B, c[0, 2].B, c[1, 0].B, c[1, 1].B, c[1, 2].B, c[2, 0].B, c[2, 1].B, c[2, 2].B); bmp.SetPixel(y, x, Color.FromArgb(red, green, blue)); } } img.UnlockBitmap(); return bmp; }
public static Bitmap GetNoAlphaBitmap(DevImage img) { Bitmap bmp = img.BmpImage; for (int column = 0; column < img.Width; column++) { for (int row = 0; row < img.Height; row++) { Color color = Color.FromArgb(img.GetPixel(column, row).R, img.GetPixel(column, row).G, img.GetPixel(column, row).B); bmp.SetPixel(column, row, color); } } return bmp; }
public ViewDevImage(Size imagesize) { m_ImageReSize = imagesize; m_dImage = new DevImage(m_ImageReSize.Width, m_ImageReSize.Height); }