コード例 #1
0
 public Form1()
 {
     InitializeComponent();
     this.anyChanges = false;
     tile            = 0;
     this.buffer     = BitmapExtensions.CreateBitmap(this.Width, this.Height);
     this.gfx        = Graphics.FromImage(buffer);
     this.drawer     = new Drawer2D();
     this.location   = new GameEngine.Location(new TileMap(null, int.Parse(this.tWidth.Text), int.Parse(this.tHeight.Text)));
 }
コード例 #2
0
ファイル: frmEditor.cs プロジェクト: taarna23/TWMapEditor
        public void ReefreshMapView()
        {
            if (Working_MAP != null)
            {
                picMap.Width  = Working_MAP.D2M.MapWidth;
                picMap.Height = Working_MAP.D2M.MapHeight;

                if (trackZoom.Value < 100)
                {
                    _MapBuffer = BitmapExtensions.ResizeImage(Working_MAP.D2M.GetLayerImage(), new Size(Working_MAP.D2M.MapWidth / 100 * trackZoom.Value, Working_MAP.D2M.MapHeight / 100 * trackZoom.Value));
                }
                else
                {
                    _MapBuffer = Working_MAP.D2M.GetLayerImage();
                }
                picMap.Invalidate();
            }
        }
コード例 #3
0
            private ImgInfo ReadImage(Stream _stream, Int32 pIndex)
            {
                ImgInfo _ImgInfo = new ImgInfo();

                _ImgInfo.NumByte = ReadByte(_stream);
                _ImgInfo.ImgIdx  = 0;
                _ImgInfo._Short2 = 0;
                _ImgInfo._Short3 = 0;
                _ImgInfo._Short4 = 0;
                if (_ImgInfo.NumByte == 0)
                {
                    _ImgInfo.ImgIdx  = ReadInt16(_stream);
                    _ImgInfo._Short2 = ReadInt16(_stream);
                    _ImgInfo._Short3 = ReadInt16(_stream);
                    _ImgInfo._Short4 = ReadInt16(_stream);
                }
                else if (_ImgInfo.NumByte == 3)
                {
                    _ImgInfo.ImgIdx = ReadInt16(_stream);
                }
                else if (_ImgInfo.NumByte == 4)
                {
                    _ImgInfo.ImgIdx  = ReadInt16(_stream);
                    _ImgInfo._Short2 = ReadInt16(_stream);
                    _ImgInfo._Short3 = ReadInt16(_stream);
                }
                else
                {
                    //!--Error
                }

                _ImgInfo.Width  = ReadInt32(_stream);
                _ImgInfo.Height = ReadInt32(_stream);

                if (_ImgInfo.NumByte != 0)
                {
                    _ImgInfo.PaletteData = new Byte[512];
                    ReadBytes(_stream, 512, ref _ImgInfo.PaletteData);

                    List <System.Windows.Media.Color> colors = new List <System.Windows.Media.Color>();
                    Bitmap _bp2       = BitmapExtensions.BitmapSourceFromArray(_ImgInfo.PaletteData, 16, 16, 16);
                    Bitmap bm2        = new Bitmap(_bp2);
                    int    FuchsiaIdx = 0;
                    bool   ff         = false;
                    for (int i = 0; i < 16; ++i)
                    {
                        for (int j = 0; j < 16; ++j)
                        {
                            Color c = bm2.GetPixel(j, i);
                            if (ff == false)
                            {
                                if (c.ToArgb() == Color.Fuchsia.ToArgb())
                                {
                                    ff = true;
                                }
                                else
                                {
                                    FuchsiaIdx++;
                                }
                            }

                            colors.Add(System.Windows.Media.Color.FromRgb(c.R, c.G, c.B));
                        }
                    }
                    //bm2.Save("C:\\b" + string.Format("\\{0}_Palette.png", pIndex), ImageFormat.Png);
                    BitmapPalette _Pl = new BitmapPalette(colors);

                    _ImgInfo.ChunkCount = ReadInt32(_stream);

                    if (_ImgInfo.ChunkCount - 1 >= 0)
                    {
                        _ImgInfo.X2Size = ReadInt32(_stream);
                        Byte[] ImgD = Enumerable.Repeat((byte)FuchsiaIdx, _ImgInfo.Width * _ImgInfo.Height * _ImgInfo.NumByte).ToArray(); //new Byte[_ImgInfo.Width * _ImgInfo.Height * _ImgInfo.NumByte];
                        for (int ChkIdx = 0; ChkIdx < _ImgInfo.ChunkCount; ++ChkIdx)
                        {
                            ImgEncodeRow nImg = new ImgEncodeRow();
                            Read <ChunkInfo>(_stream, ref nImg.Info);

                            nImg.Raw = new Byte[nImg.Info.ChunkSize];
                            ReadBytes(_stream, (uint)nImg.Info.ChunkSize, ref nImg.Raw);
                            int _Row = nImg.Info.Row;
                            int _Pos = nImg.Info.Pos;
                            nImg.Raw.CopyTo(ImgD, _Row * _ImgInfo.Width + _Pos);
                        }

                        Bitmap _bp = BitmapExtensions.BitmapSourceFromArray(ImgD, _ImgInfo.Width, _ImgInfo.Height, _ImgInfo.NumByte * 8, _Pl);
                        Bitmap bm  = new Bitmap(_bp);
                        bm.MakeTransparent(Color.Fuchsia);
                        _ImgInfo.Img = bm;
                        //bm.Save("C:\\b" + string.Format("\\{0}.png", _ImgInfo.ImgIdx), ImageFormat.Png);
                    }
                    _ImgInfo.RelativeY = ReadInt32(_stream);
                    _ImgInfo.RelativeX = ReadInt32(_stream);

                    Trace.WriteLine(string.Format("Idx {0}\tINT [{1},{2}]\t\tW:{3}\tH:{4}", _ImgInfo.ImgIdx, _ImgInfo.RelativeY, _ImgInfo.RelativeX, _ImgInfo.Width, _ImgInfo.Height));
                }

                return(_ImgInfo);
            }