Ejemplo n.º 1
0
        private void otevřítToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                myMap map = bitMapReader.Read(openFileDialog1.OpenFile());
                textShower.AppendText(map.usefullInfo());
                Bitmap pixmap   = new Bitmap(map.GetWidth(), map.GetHeight());
                int    position = 0;
                int    skip     = (map.PixelAmount() / map.GetHeight()) - map.GetWidth();

                for (int i = map.GetHeight() - 1; i >= 0; i--)
                {
                    for (int j = 0; j < map.GetWidth(); j++)
                    {
                        if (map.Pixel(position) == false)
                        {
                            pixmap.SetPixel(j, i, Color.Black);
                        }
                        else
                        {
                            pixmap.SetPixel(j, i, Color.White);
                        }
                        position++;
                    }
                    position += skip;
                }
                pictureBox1.Image = pixmap;
                dr = new Drawer(pixmap);
            }
            toolStrip1.Show();
        }
        public static myMap Read(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            char   first  = reader.ReadChar();
            char   second = reader.ReadChar();
            string prefix = first.ToString() + second;

            myMap        map;
            List <Int32> bigwords   = new List <Int32>();
            List <Int16> smallwords = new List <Int16>();
            List <byte>  pixels     = new List <byte>();

            int faser = 0;

            bigwords.Add(reader.ReadInt32());
            for (int i = 0; i < 2; i++)
            {
                smallwords.Add(reader.ReadInt16()); faser += 1 * 2;
            }
            for (int i = 0; i < 4; i++)
            {
                bigwords.Add(reader.ReadInt32()); faser += 1 * 4;
            }
            for (int i = 0; i < 2; i++)
            {
                smallwords.Add(reader.ReadInt16()); faser += 1 * 4;
            }
            for (int i = 0; i < 6; i++)
            {
                bigwords.Add(reader.ReadInt32()); faser += 1 * 4;
            }

            map = new myMap(prefix, bigwords, smallwords);

            for (int i = faser; i < map.OffsetToImage() - 2; i++)
            {
                byte a = reader.ReadByte();
                faser++;
            }

            for (int i = faser; i < map.GetSizeInBytes() - 2; i++)
            {
                pixels.Add(reader.ReadByte());
                faser++;
            }

            map.setPixelData(pixels);

            return(map);
        }