示例#1
0
        private void btnLoadReplacementFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog  openDialog = new OpenFileDialog();
            Nullable <bool> result     = openDialog.ShowDialog();

            if (result == true)
            {
                byte[] replacementFile;
                if (openDialog.FileName.ToLower().Contains(".png") || openDialog.FileName.ToLower().Contains(".bmp"))
                {
                    ImageCoder imageCoder = new ImageCoder();
                    imageCoder.Convert(new Bitmap(openDialog.FileName));
                    List <byte> convertedImage = new List <byte>();
                    // testing out using part of existing header TODO
                    BlitzGameFile selectedGame   = (BlitzGameFile)lbGameFiles.SelectedItem;
                    BlitzGraphic  currentGraphic = GetBlitzGraphic(selectedGame);
                    convertedImage.AddRange(Blitz2000Header.CreateNFLBlitz2000Header(imageCoder.Width, imageCoder.Height, imageCoder.HasAlpha, (byte)imageCoder.n64ImageType, currentGraphic.IRX, currentGraphic.IRY));
                    convertedImage.AddRange(imageCoder.Data);
                    if (imageCoder.Palette != null)
                    {
                        convertedImage.AddRange(imageCoder.Palette);
                    }
                    replacementFile     = convertedImage.ToArray();
                    openDialog.FileName = openDialog.FileName.Split('.')[0] + ".wms";
                    File.WriteAllBytes(openDialog.FileName, convertedImage.ToArray());
                }
                replacementFile = File.ReadAllBytes(openDialog.FileName);
                InsertReplacementFile(replacementFile);
            }
        }
示例#2
0
        public ActionResult CheckImage()
        {
            string     value;
            ImageCoder img = new ImageCoder();

            byte[] bytes = img.GetImageByte(out value);
            Session["ImgCode"] = value;

            return(File(bytes, "image/png"));
        }
示例#3
0
文件: MainVm.cs 项目: ki0ki0/WiFiMap
        public void OnNewProject(object param)
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "Select image with the plan";
            openFileDialog.Filter = "Images|*.jpg;*.png" +
                                    "|All Files|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                var project       = new Project();
                var bitmapDecoder = BitmapDecoder.Create(new Uri(openFileDialog.FileName), BitmapCreateOptions.None,
                                                         BitmapCacheOption.Default);
                var bitmap = bitmapDecoder.Frames[0];
                project.Bitmap = ImageCoder.ImageToByte(bitmap);
                ScanVm.Project = project;
            }
        }
示例#4
0
        /// <summary>
        /// When a user chnages the selected n64 graphics type, we convert it to that type.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbImageType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbGameFiles.SelectedValue == null)
            {
                return;
            }
            BlitzGraphic currentGraphic = GetBlitzGraphic((BlitzGameFile)lbGameFiles.SelectedItem);

            if (cbImageType.IsDropDownOpen && (N64ImageType)Enum.Parse(typeof(N64ImageType), currentGraphic.ImageType) != (N64ImageType)cbImageType.SelectedValue)
            {
                ImageCoder imageCoder = new ImageCoder();
                imageCoder.ConvertTo(currentGraphic.BlitzImage, (N64ImageType)cbImageType.SelectedValue);
                List <byte> convertedImage = new List <byte>();
                convertedImage.AddRange(Blitz2000Header.CreateNFLBlitz2000Header(imageCoder.Width, imageCoder.Height, imageCoder.HasAlpha, (byte)imageCoder.n64ImageType, currentGraphic.IRX, currentGraphic.IRY));
                convertedImage.AddRange(imageCoder.Data);
                InsertReplacementFile(convertedImage.ToArray());
            }
        }
示例#5
0
        private void btnInsertNewFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog  openDialog = new OpenFileDialog();
            Nullable <bool> result     = openDialog.ShowDialog();

            if (result == true)
            {
                byte[] replacementFile;
                if (openDialog.FileName.ToLower().Contains(".png") || openDialog.FileName.ToLower().Contains(".bmp"))
                {
                    ImageCoder imageCoder = new ImageCoder();
                    imageCoder.Convert(new Bitmap(openDialog.FileName));
                    List <byte> convertedImage = new List <byte>();
                    convertedImage.AddRange(Blitz2000Header.CreateNFLBlitz2000Header(imageCoder.Width, imageCoder.Height, imageCoder.HasAlpha, (byte)imageCoder.n64ImageType));
                    convertedImage.AddRange(imageCoder.Data);
                    if (imageCoder.Palette != null)
                    {
                        convertedImage.AddRange(imageCoder.Palette);
                    }
                    replacementFile     = convertedImage.ToArray();
                    openDialog.FileName = openDialog.FileName.Split('.')[0] + ".wms";
                    File.WriteAllBytes(openDialog.FileName, convertedImage.ToArray());
                }
                replacementFile = File.ReadAllBytes(openDialog.FileName);
                //byte[] compressedFileBytes = MiniLZO.MiniLZO.Compress(replacementFile);
                byte[] compressedFileBytes = MiniLZO.MiniLZO.CompressWithPrecomp2(openDialog.FileName);
                int    compressedSize      = compressedFileBytes.Length;
                if ((compressedSize & 1) != 0)
                {
                    List <byte> tempList = compressedFileBytes.ToList();
                    tempList.Add(00);
                    compressedFileBytes = tempList.ToArray();
                }
                long currentTableOffset;
                int  fileTableEntrySize = gameInfo.maxFileNameLenght + gameInfo.filePositionLength + gameInfo.decompressedLenght + gameInfo.compressedLenght;
                int  fileCount;
                using (var fs = new FileStream(romLocation, FileMode.Open, FileAccess.ReadWrite))
                {
                    //Update tableOffsetLocation
                    currentTableOffset = BitsHelper.GetNumberFromBytes(BitsHelper.ReadBytesFromFileStream(fs, gameInfo.FileSystemOffset + 8, 4).ToArray());
                    long   newTableOffset      = currentTableOffset + compressedFileBytes.Length;
                    byte[] newTableOffsetBytes = BitConverter.GetBytes((Int32)newTableOffset);
                    Array.Reverse(newTableOffsetBytes);
                    BitsHelper.WritBytesToFileStream(newTableOffsetBytes, fs, gameInfo.FileSystemOffset + 8);
                    fileCount = BitsHelper.GetNumberFromBytes(BitsHelper.ReadBytesFromFileStream(fs, gameInfo.FileSystemOffset + 12, 4).ToArray());
                    byte[] newfileCountBytes = BitConverter.GetBytes((Int32)(fileCount + 1));
                    Array.Reverse(newfileCountBytes);
                    BitsHelper.WritBytesToFileStream(newfileCountBytes, fs, gameInfo.FileSystemOffset + 12);
                }

                //move the files that are after this entry
                byte[] fullRom   = File.ReadAllBytes(romLocation);
                byte[] fileTable = fullRom.ToList().GetRange((int)(currentTableOffset + gameInfo.FileSystemOffset), fileTableEntrySize * fileCount).ToArray();
                //Write new file
                BlitzGameFile newGameFile = new BlitzGameFile()
                {
                    fileName            = "~" + openDialog.FileName.Split('\\').Last(),
                    compressedSize      = compressedSize,
                    decompressedSize    = replacementFile.Length,
                    fileOffset          = currentTableOffset,
                    fileTableEntryStart = currentTableOffset + gameInfo.FileSystemOffset + compressedFileBytes.Length + (fileTableEntrySize * (fileCount))
                };

                RomEditor.ByteArrayToFile(romLocation, compressedFileBytes, (int)newGameFile.fileOffset);
                // fix/write to file table
                RomEditor.ByteArrayToFile(romLocation, fileTable, (int)(currentTableOffset + gameInfo.FileSystemOffset) + compressedFileBytes.Length);
                WriteNewFileTableToRom(newGameFile);
                LoadRom(romLocation);
            }
        }