private ImageSource GetGlobalMapImagefFromPcx(string aFileName) { string _path = Path.Combine(this.FGlobalMapsFolder, aFileName); PcxObject _pcx = null; if (File.Exists(_path)) { _pcx = new PcxObject(aFileName); using (FileStream input = new FileStream(_path, FileMode.Open, FileAccess.Read)) _pcx.Load(input); } else { if (this.SlfFile != null) { SlfFile.Record _record = this.SlfFile.Records .SingleOrDefault(x => x.FileName.ToUpperInvariant() == aFileName.ToUpperInvariant()); if (_record != null) { _pcx = new PcxObject(aFileName); using (MemoryStream input = new MemoryStream(_record.Data)) _pcx.Load(input); } } } if (_pcx == null) { return(null); } List <Color> _palette = _pcx.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); BitmapPalette _pb = new BitmapPalette(_palette); PixelFormat _pf = PixelFormats.Indexed8; BitmapSource _bitmap = BitmapSource.Create( _pcx.Width, _pcx.Height, 96, 96, _pf, _pb, _pcx.ImageData, _pcx.Width * _pf.BitsPerPixel / 8); return(_bitmap); }
public void Execute(object parameter) { PcxTestViewModel _viewModel = (PcxTestViewModel)parameter; try { _viewModel.StatusString = String.Empty; _viewModel.ResultString = String.Empty; PcxObject _pcx = PcxObject.LoadPcx(_viewModel.FileName); _viewModel.ResultString = _pcx.ToString(); List <Color> _palette = _pcx.ColorPalette .Select(x => new Color() { A = 255, R = x.Red, G = x.Green, B = x.Blue }) .ToList(); PixelFormat _pf = PixelFormats.Indexed8; _viewModel.PcxImage = BitmapSource.Create( _pcx.Width, _pcx.Height, 96, 96, _pf, new BitmapPalette(_palette), _pcx.ImageData, _pcx.Width * _pf.BitsPerPixel / 8); _viewModel.StatusString = "Done"; } catch (Exception exc) { _viewModel.ErrorString = Common.GetErrorString(exc); } }