/// <summary> /// Recibe una imagen y la retorna con un filtro del tipo inventado aplicado /// </summary> /// <param name="image">Imagen a la cual se le va a plicar el filtro.</param> /// <returns>Imagen con el filtro aplicado</returns> public IPicture Filter(IPicture image) { Debug.Assert(image != null); IPicture invento = image.Clone(); for (int x = 0; x < invento.Width; x++) { for (int y = 0; y < invento.Height; y++) { Color colorOriginal = invento.GetColor(x, y); byte rOriginal = colorOriginal.R; byte gOriginal = colorOriginal.G; byte bOriginal = colorOriginal.B; byte rNeg = Convert.ToByte(Math.Abs(rOriginal / 2)); byte gNeg = Convert.ToByte(Math.Abs(gOriginal / 10)); byte bNeg = Convert.ToByte(Math.Abs(bOriginal / 5)); var rand = new Random(); Color colorCualquiera; colorCualquiera = Color.FromArgb(rNeg, gNeg, bNeg); // colorCualquiera = Color.FromArgb(rNeg, gNeg, bNeg); invento.SetColor(x, y, colorCualquiera); } } return(invento); }
/// <summary> /// Recibe una imagen y la retorna con un filtro del tipo negativo aplicado /// </summary> /// <param name="image">Imagen a la cual se le va a plicar el filtro.</param> /// <returns>Imagen con el filtro aplicado</returns> public IPicture Filter(IPicture image) { Debug.Assert(image != null); IPicture negativo = image.Clone(); for (int x = 0; x < negativo.Width; x++) { for (int y = 0; y < negativo.Height; y++) { Color colorOriginal = negativo.GetColor(x, y); byte rOriginal = colorOriginal.R; byte gOriginal = colorOriginal.G; byte bOriginal = colorOriginal.B; byte rNeg = Convert.ToByte(Math.Abs(rOriginal - byte.MaxValue)); byte gNeg = Convert.ToByte(Math.Abs(gOriginal - byte.MaxValue)); byte bNeg = Convert.ToByte(Math.Abs(bOriginal - byte.MaxValue)); Color colorNegativo; colorNegativo = Color.FromArgb(rNeg, gNeg, bNeg); negativo.SetColor(x, y, colorNegativo); } } return(negativo); }
public Color[,] CrearMatriz(IPicture image, int x, int y) { Color[,] matriz = new Color[3, 3]; matriz[0, 0] = image.GetColor(Math.Max(x - 1, 0), Math.Max(y - 1, 0)); matriz[1, 0] = image.GetColor(x, Math.Max(y - 1, 0)); matriz[2, 0] = image.GetColor(Math.Min(x + 1, image.Width - 1), Math.Max(y - 1, 0)); matriz[0, 1] = image.GetColor(Math.Max(x - 1, 0), y); matriz[1, 1] = image.GetColor(x, y); matriz[2, 1] = image.GetColor(Math.Min(x + 1, image.Width - 1), y); matriz[0, 2] = image.GetColor(Math.Max(x - 1, 0), Math.Min(y + 1, image.Height - 1)); matriz[1, 2] = image.GetColor(x, Math.Min(y + 1, image.Height - 1)); matriz[2, 2] = image.GetColor(Math.Min(x + 1, image.Width - 1), Math.Min(y + 1, image.Height - 1)); return(matriz); }
public void SavePicture(IPicture p, string path) { int width = p.Width; int height = p.Height; using (Image <Rgba32> img = new Image <Rgba32>(width, height)) // creates a new image with all the pixels set as transparent { for (int h = 0; h < p.Height; h++) { for (int w = 0; w < p.Width; w++) { Color c = p.GetColor(w, h); img[w, h] = new Rgba32(c.R, c.G, c.B, c.A); } } img.Save(path); } }
public IPicture Filter(IPicture image) { for (int i = 0; i < image.Width; i++) { for (int j = 0; j < image.Height; j++) { Color color = image.GetColor(i, j); if (Math.Min(color.R, Math.Min(color.G, color.B)) > limit) { image.SetColor(i, j, Color.FromArgb(255, 255, 255)); } else { image.SetColor(i, j, Color.FromArgb(0, 0, 0)); } } } return(image); }
/// <summary> /// Recibe una imagen y la retorna con un filtro de escala de grises aplicado. /// </summary> /// <param name="image">Imagen a la que se le va a aplicar el filtro.</param> /// <returns>Imagen con el filtro aplicado.</returns> public IPicture Filter(IPicture image) { Debug.Assert(image != null); IPicture greyScale = image.Clone(); for (int x = 0; x < greyScale.Width; x++) { for (int y = 0; y < greyScale.Height; y++) { Color colorOriginal = greyScale.GetColor(x, y); byte rOriginal = colorOriginal.R; byte gOriginal = colorOriginal.G; byte bOriginal = colorOriginal.B; int luma = (int)((rOriginal * 0.3) + (gOriginal * 0.59) + (bOriginal * 0.11)); Color colorGris; colorGris = Color.FromArgb(luma, luma, luma); greyScale.SetColor(x, y, colorGris); } } return(greyScale); }
/// <summary> /// Transforma una IPicture en un Bitmap .NET. /// </summary> /// <param name="picture">la IPicture</param> /// <returns>el Bitmap</returns> public Bitmap GetBitmap(IPicture picture) { Debug.Assert(picture != null); Bitmap bitmap = new Bitmap(picture.Width - 10, picture.Height - 10); BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Int32 bitsPerPixel = 4; Int32 offset = bitmapData.Stride - (bitmapData.Width * bitsPerPixel); unsafe { byte *imagePointer1 = (byte *)bitmapData.Scan0; for (int y = 0; y < bitmapData.Height; y++) { for (int x = 0; x < bitmapData.Width; x++) { Int32 color = picture.GetColor(x, y).ToArgb(); imagePointer1[0] = (byte)((color & 0xFF0000) >> 16); imagePointer1[1] = (byte)((color & 0xFF00) >> 8); imagePointer1[2] = (byte)((color & 0xFF)); imagePointer1[3] = (byte)((color & 0xFF000000) >> 24);; imagePointer1 += bitsPerPixel; } imagePointer1 += offset; } } bitmap.UnlockBits(bitmapData); Debug.Assert(bitmap != null); return(bitmap); }