Exemplo n.º 1
0
        private BitmapSource ImageFromClipboardDib()
        {
            MemoryStream ms = Clipboard.GetData("DeviceIndependentBitmap") as MemoryStream;

            if (ms != null)
            {
                byte[] dibBuffer = new byte[ms.Length];
                ms.Read(dibBuffer, 0, dibBuffer.Length);

                BITMAPINFOHEADER infoHeader =
                    BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer);

                int fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
                int infoHeaderSize = infoHeader.biSize;
                int fileSize       = fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage;

                BITMAPFILEHEADER fileHeader = new BITMAPFILEHEADER();
                fileHeader.bfType      = BITMAPFILEHEADER.BM;
                fileHeader.bfSize      = fileSize;
                fileHeader.bfReserved1 = 0;
                fileHeader.bfReserved2 = 0;
                fileHeader.bfOffBits   = fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4;

                byte[] fileHeaderBytes =
                    BinaryStructConverter.ToByteArray <BITMAPFILEHEADER>(fileHeader);

                MemoryStream msBitmap = new MemoryStream();
                msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize);
                msBitmap.Write(dibBuffer, 0, dibBuffer.Length);
                msBitmap.Seek(0, SeekOrigin.Begin);

                return(BitmapFrame.Create(msBitmap));
            }
            return(null);
        }
Exemplo n.º 2
0
        public void LoadClipObject(ClipObject clipObject)
        {
            var ms = (MemoryStream) new DataObjectConverter().GetClipObjectData(clipObject);

            byte[] dibBuffer = new byte[ms.Length];
            ms.Read(dibBuffer, 0, dibBuffer.Length);

            BITMAPINFOHEADER infoHeader =
                BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer);

            int fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
            int infoHeaderSize = infoHeader.biSize;
            int fileSize       = fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage;

            BITMAPFILEHEADER fileHeader = new BITMAPFILEHEADER();

            fileHeader.bfType      = BITMAPFILEHEADER.BM;
            fileHeader.bfSize      = fileSize;
            fileHeader.bfReserved1 = 0;
            fileHeader.bfReserved2 = 0;
            fileHeader.bfOffBits   = fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4;

            byte[] fileHeaderBytes =
                BinaryStructConverter.ToByteArray <BITMAPFILEHEADER>(fileHeader);

            MemoryStream msBitmap = new MemoryStream();

            msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize);
            msBitmap.Write(dibBuffer, 0, dibBuffer.Length);
            msBitmap.Seek(0, SeekOrigin.Begin);

            _image.Source = BitmapFrame.Create(msBitmap);
        }
Exemplo n.º 3
0
        public static BitmapSource ImageFromClipboardDib()
        {
            var ms = Clipboard.GetData("DeviceIndependentBitmap") as MemoryStream;

            if (ms == null)
            {
                return(null);
            }

            var dibBuffer = new byte[ms.Length];

            ms.Read(dibBuffer, 0, dibBuffer.Length);

            var infoHeader     = BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer);
            var fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
            var infoHeaderSize = infoHeader.biSize;
            var fileSize       = fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage;

            var fileHeader = new BITMAPFILEHEADER
            {
                bfType      = BITMAPFILEHEADER.BM,
                bfSize      = fileSize,
                bfReserved1 = 0,
                bfReserved2 = 0,
                bfOffBits   = fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4
            };

            var fileHeaderBytes = BinaryStructConverter.ToByteArray(fileHeader);
            var msBitmap        = new MemoryStream();

            msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize);
            msBitmap.Write(dibBuffer, 0, dibBuffer.Length);
            msBitmap.Seek(0, SeekOrigin.Begin);
            return(BitmapFrame.Create(msBitmap));
        }
Exemplo n.º 4
0
        public void DoLogin(string sLogin, string sPassword)
        {
            _loginAccountRequest = new _login_account_request_cllo();
            // Init Arrays //
            _loginAccountRequest.szAccountID = new byte[13];
            _loginAccountRequest.szPassword  = new byte[13];
            _defaulSet.id_account            = new byte[13];

            // Fill in login and password bytes //
            var login    = Encoding.ASCII.GetBytes(sLogin);
            var password = Encoding.ASCII.GetBytes(sPassword);

            // Fill in DefaultSet
            login.CopyTo(_defaulSet.id_account, 0);
            // Resize to 13 //
            Array.Resize(ref login, 13);
            Array.Resize(ref password, 13);
            // XOR Encrypt //
            EnCryptString(login, 13, _cryptyKeyInformLocl.byPlus, _cryptyKeyInformLocl.wKey);
            EnCryptString(password, 13, _cryptyKeyInformLocl.byPlus, _cryptyKeyInformLocl.wKey);
            // Copy XOR encrypted data to pack //
            login.CopyTo(_loginAccountRequest.szAccountID, 0);
            password.CopyTo(_loginAccountRequest.szPassword, 0);
            // Set server type //
            _loginAccountRequest.byServerType = 0;

            _loginAccountRequest.header.m_wSize     = _loginAccountRequest.size();
            _loginAccountRequest.header.m_byType    = 21;
            _loginAccountRequest.header.m_bySubType = 3;

            byte[] bLoginAccountRequest = BinaryStructConverter.ToByteArray(_loginAccountRequest);

            Send(Client, bLoginAccountRequest);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a BitmapFrame from a buffer containing a DIB.
        /// </summary>
        public static BitmapFrame CreateBitmapFrameFromDibBytes(byte[] dibBuffer)
        {
            BITMAPINFOHEADER infoHeader = BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer);

            int fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
            int infoHeaderSize = infoHeader.biSize;
            int fileSize       = fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage;

            BITMAPFILEHEADER fileHeader = new BITMAPFILEHEADER
            {
                bfType      = BITMAPFILEHEADER.BM,
                bfSize      = fileSize,
                bfReserved1 = 0,
                bfReserved2 = 0,
                bfOffBits   = fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4
            };

            byte[] fileHeaderBytes = BinaryStructConverter.ToByteArray(fileHeader);

            MemoryStream msBitmap = new MemoryStream();

            msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize);
            msBitmap.Write(dibBuffer, 0, dibBuffer.Length);
            msBitmap.Seek(0, SeekOrigin.Begin);

            return(BitmapFrame.Create(msBitmap));
        }
        /// <summary>
        /// Gets the bitmap source from clipboard asynchronous.
        /// </summary>
        /// <returns>Task&lt;System.Object&gt;.</returns>
        public Task <object> GetBitmapSourceFromClipboardAsync()
        {
            if (System.Windows.Clipboard.GetData("DeviceIndependentBitmap") is MemoryStream iMemoryStream)
            {
                byte[] dibBuffer = new byte[Convert.ToInt32(iMemoryStream.Length - 1) + 1];
                iMemoryStream.Read(dibBuffer, 0, dibBuffer.Length);

                BITMAPINFOHEADER iInfoHeader = BinaryStructConverter.FromByteArray <BITMAPINFOHEADER>(dibBuffer);

                int fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
                int infoHeaderSize = iInfoHeader.biSize;
                int fileSize       = fileHeaderSize + iInfoHeader.biSize + iInfoHeader.biSizeImage;

                BITMAPFILEHEADER iFileHeader = new BITMAPFILEHEADER
                {
                    bfType      = BITMAPFILEHEADER.BM,
                    bfSize      = fileSize,
                    bfReserved1 = 0,
                    bfReserved2 = 0,
                    bfOffBits   = fileHeaderSize + infoHeaderSize + iInfoHeader.biClrUsed * 4
                };

                byte[] fileHeaderBytes = BinaryStructConverter.ToByteArray <BITMAPFILEHEADER>(iFileHeader);

                MemoryStream iBitmapStream = new MemoryStream();
                iBitmapStream.Write(fileHeaderBytes, 0, fileHeaderSize);
                iBitmapStream.Write(dibBuffer, 0, dibBuffer.Length);
                iBitmapStream.Seek(0, SeekOrigin.Begin);

                return(Task.FromResult <object>(BitmapFrame.Create(iBitmapStream)));
            }
            return(Task.FromResult <object>(null));
        }
        public static MemoryStream GetConvertedBytes(ref MemoryStream ms)
        {
            if (ms == null)
            {
                return(null);
            }
            byte[] dibBuffer = new byte[ms.Length];
            ms.Read(dibBuffer, 0, dibBuffer.Length);
            BITMAPV5HEADER   infoHeader     = BinaryStructConverter.FromByteArray <BITMAPV5HEADER>(dibBuffer);
            int              fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
            int              infoHeaderSize = infoHeader.bV5Size;
            int              fileSize       = fileHeaderSize + infoHeader.bV5Size + infoHeader.bV5SizeImage;
            BITMAPFILEHEADER fileHeader     = new BITMAPFILEHEADER();

            fileHeader.bfType      = BITMAPFILEHEADER.BM;
            fileHeader.bfSize      = fileSize;
            fileHeader.bfReserved1 = 0;
            fileHeader.bfReserved2 = 0;
            fileHeader.bfOffBits   = fileHeaderSize + infoHeaderSize + infoHeader.bV5ClrUsed * 4;
            byte[]       fileHeaderBytes = BinaryStructConverter.ToByteArray <BITMAPFILEHEADER>(fileHeader);
            MemoryStream msBitmap        = new MemoryStream();

            msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize);
            msBitmap.Write(dibBuffer, 0, dibBuffer.Length);
            msBitmap.Seek(0, SeekOrigin.Begin);
            return(msBitmap);
        }
Exemplo n.º 8
0
 public static void WriteTmp(string path, Default_Set data)
 {
     if (!File.Exists(path))
     {
         File.Create(path);
     }
     data.encrypt();
     byte[] bDefaultSet = BinaryStructConverter.ToByteArray(data);
     File.WriteAllBytes(path, bDefaultSet);
 }
Exemplo n.º 9
0
        private void CryptoKeyRequest(Socket client)
        {
            _crypty_key_request_cllo cryptyKeyRequest = new _crypty_key_request_cllo();

            cryptyKeyRequest.header.m_wSize     = cryptyKeyRequest.size();
            cryptyKeyRequest.header.m_byType    = 21;
            cryptyKeyRequest.header.m_bySubType = 12;
            byte[] bCryptyKeyRequest = BinaryStructConverter.ToByteArray(cryptyKeyRequest);

            Send(client, bCryptyKeyRequest);
        }
Exemplo n.º 10
0
        void WorldListRequest(Socket client)
        {
            _world_list_request_cllo worldListRequest = new _world_list_request_cllo();

            worldListRequest.header.m_wSize     = worldListRequest.size();
            worldListRequest.header.m_byType    = 21;
            worldListRequest.header.m_bySubType = 5;
            worldListRequest.dwClientVersion    = 0;

            byte[] bWorldListRequest = BinaryStructConverter.ToByteArray(worldListRequest);
            Send(client, bWorldListRequest);
        }
Exemplo n.º 11
0
        public void SelectWordlRequest(int idServer)
        {
            _defaulSet.world_id = (ushort)idServer;
            _select_world_request_cllo selectWorldRequest = new _select_world_request_cllo();

            selectWorldRequest.header.m_wSize     = selectWorldRequest.size();
            selectWorldRequest.header.m_byType    = 21;
            selectWorldRequest.header.m_bySubType = 7;
            selectWorldRequest.wWorldIndex        = (byte)idServer;

            byte[] bSelectWorldRequest = BinaryStructConverter.ToByteArray(selectWorldRequest);
            Send(Client, bSelectWorldRequest);
        }
Exemplo n.º 12
0
        public void CloseAccountRequest(Socket client)
        {
            _push_close_request_cllo pushCloseRequest = new _push_close_request_cllo();

            pushCloseRequest.header.m_wSize     = pushCloseRequest.size();
            pushCloseRequest.header.m_byType    = 21;
            pushCloseRequest.header.m_bySubType = 9;
            pushCloseRequest.szAccountID        = new byte[13];
            pushCloseRequest.szPassword         = new byte[13];


            _loginAccountRequest.szAccountID.CopyTo(pushCloseRequest.szAccountID, 0);
            _loginAccountRequest.szPassword.CopyTo(pushCloseRequest.szPassword, 0);
            pushCloseRequest.dwAccountSerial = _defaulSet.account_serial;

            byte[] bPushCloseRequest = BinaryStructConverter.ToByteArray(pushCloseRequest);
            Send(client, bPushCloseRequest);
        }