internal static Bitmap DecodeImage(int[][] encodedImage) { var width = encodedImage[0].Length; var height = encodedImage.Length; var scale = 2; if (width <= 16) { scale = 16; } else if (width <= 8) { scale = 32; } var result = new Bitmap(width * scale, height * scale); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { var colorInt = encodedImage[y][x]; var colorLong = ColorCutter.ExpandColor(colorInt); Color color = Color.FromArgb(colorLong); color = Color.FromArgb(255, color); PasteColorToScale(x, y, scale, color, result); } } return(result); }
private void convertSingleButton_Click(object sender, EventArgs e) { var filePath = ioHandler.SelectFile(); var matrixSize = GetMatrixSize(); string error; var encodedImage = ColorCutter.EncodeImage(filePath, matrixSize[0], matrixSize[1], out error); if (!string.IsNullOrEmpty(error) || encodedImage == null) { ShowErrorNotification(error); return; } var sb = new StringBuilder(); var arrayPrefixName = GetArrayPrefixName(); var arrayElementName = string.Format("{0}00", arrayPrefixName); ioHandler.EncodeAndAddAsText(encodedImage, arrayElementName, sb); var arrayElementNames = new List <string>() { arrayElementName }; ioHandler.AddArrayDeclaration(sb, arrayPrefixName, arrayElementNames); ioHandler.SaveToFile(sb); pictureBox1.Image = TestImagesStorage.DecodeImage(encodedImage); }
internal static Bitmap GetMarioImage() { var scale = 32; var width = marioPixels[0].Length; var height = marioPixels.Length; var result = new Bitmap(width * scale, height * scale); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { var colorInt = marioPixels[y][x]; var colorLong = ColorCutter.ExpandColor(colorInt); Color color = Color.FromArgb(colorLong); color = Color.FromArgb(255, color); PasteColorToScale(x, y, scale, color, result); } } return(result); }
private void convertFolderButton_Click(object sender, EventArgs e) { var folderPath = ioHandler.SelectFolder(); var supportedExtentions = new[] { "*.jpg", "*.jpeg", "*.png", "*.bmp" }; List <string> foundFiles = new List <string>(); for (int i = 0; i < supportedExtentions.Length; i++) { var ext = supportedExtentions[i]; var extFiles = Directory.GetFiles(folderPath, ext, SearchOption.TopDirectoryOnly); if (extFiles != null && extFiles.Length > 0) { foundFiles.AddRange(extFiles); } } MessageBox.Show("Files found: " + foundFiles.Count.ToString(), "Message"); var matrixSize = GetMatrixSize(); string error; var sb = new StringBuilder(); var arrayElementPrefix = GetArrayPrefixName(); var arrayElementNames = new List <string>(); for (int i = 0; i < foundFiles.Count; i++) { var filePath = foundFiles[i]; var encodedImage = ColorCutter.EncodeImage(filePath, matrixSize[0], matrixSize[1], out error); if (!string.IsNullOrEmpty(error) || encodedImage == null) { ShowErrorNotification(error); continue; } var fileName = string.Format("{0}{1}", arrayElementPrefix, i); arrayElementNames.Add(fileName); ioHandler.EncodeAndAddAsText(encodedImage, fileName, sb); } ioHandler.AddArrayDeclaration(sb, arrayElementPrefix, arrayElementNames); ioHandler.SaveToFile(sb); //pictureBox1.Image = TestImagesStorage.DecodeImage(encodedImage); }