Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. private void ChosseBtn_Click(object sender, EventArgs e)
  2. {
  3. using (OpenFileDialog dlg = new OpenFileDialog())
  4. {
  5. dlg.Title = "Open Image";
  6. dlg.Filter = "bmp files (*.bmp)|*.bmp";
  7.  
  8. if (dlg.ShowDialog() == DialogResult.OK)
  9. {
  10. var colorCodes = this.GetColorCodes(dlg.FileName);
  11. var str = string.Join(Environment.NewLine,
  12. colorCodes.Select<int[], string>(line => string.Join(" ", line.Select<int, string>(code => string.Format("{0:X8}", code))))); // string.Format("{0:X6}", code & 0x00FFFFFF) if you want RRGGBB format
  13. textBox1.Text = str; // requires textBox1.Multiline = true, better have monospaced font
  14. }
  15. }
  16. }
  17. private int[][] GetColorCodes(string path)
  18. {
  19. var bitmap = new Bitmap(path);
  20. return Enumerable.Range(0, bitmap.Height)
  21. .Select<int, int[]>(y => Enumerable.Range(0, bitmap.Width)
  22. .Select<int, int>(x => bitmap.GetPixel(x, y).ToArgb()).ToArray()).ToArray();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement