private static DMIImageData MakeGreyscaleSquare(DMIImageData image) { FreeImageAPI.FreeImageBitmap bit = new FreeImageAPI.FreeImageBitmap(image.Bitmap); bit.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); Color grey = new Color(); grey = bit.GetPixel(2, 2); for (int i = 0; i < bit.Height; i++) { for (int j = 0; j < bit.Width; j++) { grey = Color.FromArgb(255, j, i, 0); bit.SetPixel(j, i, grey); } } image.Bitmap = bit.ToBitmap(); return(image); }
/// <summary> /// Transform a given image using a direction specific template /// </summary> /// <param name="image"></param> /// <returns>Uses pass by reference, no return</returns> private static void MakeImageTransform(DMIImageData image) { FreeImageAPI.FreeImageBitmap inMap = new FreeImageAPI.FreeImageBitmap(image.Bitmap); FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/UnathiUnder" + image.Dir + ".png"); // FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/UnathiHatGlass.png"); // FreeImageAPI.FreeImageBitmap transMap = new FreeImageAPI.FreeImageBitmap("./in/Templates/TallGreySquare.png"); inMap.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); transMap.ConvertColorDepth(FreeImageAPI.FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP); Color inCol = new Color(); Color transCol = new Color(); Color clearRead = Color.FromArgb(0, 192, 192, 192); Color clearWrite = inMap.GetPixel(0, 0); int[, ][] transStore = new int[transMap.Width, transMap.Height][]; if (image.Dir == 4) { inMap.RotateFlip(RotateFlipType.RotateNoneFlipX); } // Get the original tranformation map's colours and store in 2D jagged array for manipulation for (int i = 0; i < transMap.Height; i++) { for (int j = 0; j < transMap.Width; j++) { transCol = transMap.GetPixel(j, i); transStore[j, i] = new int[4] { transCol.A, transCol.R, transCol.G, transCol.B }; } } // Iterate through the image pixel by pixel, taking the colour from the original and applying it to // all members of the transform array with a colour that matches the location based on i and j. // Ex: if i is 10 and j is 20, all places in the array with the ARGB colour (255, 10, 20, 0) // will be replaced with the new colour. for (int i = 0; i < inMap.Height; i++) { for (int j = 0; j < inMap.Width; j++) { inCol = inMap.GetPixel(j, i); transCol = Color.FromArgb(255, j, i, 0); // transStore = StoreColReplace(transStore, transCol, inCol, transMap.Width, transMap.Height); } } // Takes the array and writes the new pixels onto the template for (int i = 0; i < transMap.Height; i++) { for (int j = 0; j < transMap.Width; j++) { Color tempCol = Color.FromArgb(transStore[j, i][0], transStore[j, i][1], transStore[j, i][2], transStore[j, i][3]); if (tempCol.Equals(clearWrite)) { tempCol = Color.FromArgb(transStore[31, 15][0], transStore[31, 15][1], transStore[31, 15][2], transStore[31, 15][3]); } transMap.SetPixel(j, i, tempCol); } } transMap.PreMultiplyWithAlpha(); if (image.Dir == 4) { transMap.RotateFlip(RotateFlipType.RotateNoneFlipX); } image.Bitmap = transMap.ToBitmap(); }