private void LoadMap(string mapName) { pathToFiles = Path.Combine(mapName, pathToConfigs); try { Regex rgx = new Regex("[^a-zA-Z0-9-]"); string key = rgx.Replace(mapName, "").ToLower().Trim(); if (configs.ContainsKey(key)) { currentConfig = configs[key]; currentImage = new Bitmap(currentConfig.rows * currentConfig.ImageSize, currentConfig.cols * currentConfig.ImageSize); using (Graphics g = Graphics.FromImage(currentImage)) { for (int col = 0; col < currentConfig.cols; col++) { for (int row = 0; row < currentConfig.rows; row++) { string imageName = Path.Combine(pathToFiles + key, (col + currentConfig.colsStart).ToString("D2") + (row + currentConfig.rowsStart).ToString("D2") + ".dds"); int x = currentConfig.ImageSize * (row + currentConfig.rowsStart); int y = currentConfig.ImageSize * (col + currentConfig.colsStart); try { using (DevIL.ImageImporter imImport = new DevIL.ImageImporter()) { g.DrawImage(LoadImage(imImport, new MemoryStream(File.ReadAllBytes(imageName)), currentConfig.ImageSize, currentConfig.ImageSize), x, y, currentConfig.ImageSize, currentConfig.ImageSize); } } catch { g.DrawImage(new Bitmap(currentConfig.ImageSize, currentConfig.ImageSize), x, y, currentConfig.ImageSize, currentConfig.ImageSize); } } } } pictureBox_path.Width = currentConfig.rows * currentConfig.ImageSize; pictureBox_path.Height = currentConfig.cols * currentConfig.ImageSize; pictureBox_path.BackgroundImage = currentImage; pictureBox_path.Refresh(); comboBox_lists.Items.Clear(); foreach (string map in configs.Keys) { comboBox_lists.Items.Add(map); } autoSlected = true; comboBox_lists.SelectedIndex = comboBox_lists.FindString(key); autoSlected = false; Loaded = true; } else { JMessageBox.Show(this, "Unable to load images for :" + mapName + ".\rWill not continue without graphic suport!"); return; } } catch (Exception e) { JMessageBox.Show(this, "Unable to load config:" + e.ToString()); return; } }
/// <summary> /// Gets .png format image of the .dds texture. /// </summary> /// <returns>.png format image of the .dds texture.</returns> public override unsafe Image GetImage() { var data = this.GetDDSArray(); using (var DataStream = new MemoryStream(data)) using (var ResultStream = new MemoryStream()) using (var importer = new DevIL.ImageImporter()) using (var exporter = new DevIL.ImageExporter()) { using (var InterImage = importer.LoadImageFromStream(DataStream)) { exporter.SaveImageToStream(InterImage, DevIL.ImageType.Png, ResultStream); var result = Image.FromStream(ResultStream); return(result); } } }
public SD.Bitmap LoadImage(DevIL.ImageImporter ImImport, MemoryStream mStream, int width = 128, int height = 128) { try { DevIL.Image IconImg = ImImport.LoadImageFromStream(mStream); IconImg.Bind(); var img = new SD.Bitmap(IconImg.Width, IconImg.Height, SDI.PixelFormat.Format32bppArgb); SD.Rectangle rect = new SD.Rectangle(0, 0, IconImg.Width, IconImg.Height); SDI.BitmapData data = img.LockBits(rect, SDI.ImageLockMode.WriteOnly, SDI.PixelFormat.Format32bppArgb); DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, IconImg.Width, IconImg.Height, 1, DevIL.DataFormat.BGRA, DevIL.DataType.UnsignedByte, data.Scan0); img.UnlockBits(data); return(img); } catch { return(new SD.Bitmap(width, height)); } }
public SD.Bitmap GetBitmap(string FileName, int width = 128, int height = 128, bool foreceResize = false) { if (!SurfacesPCK.IsLoaded) { return(new SD.Bitmap(width, height)); } try { string NameFound = (from n in Names where n.ToLower() == FileName.ToLower() select n).FirstOrDefault(); if (string.IsNullOrEmpty(NameFound)) { return(new SD.Bitmap(width, height)); } byte[] imgData = SurfacesPCK.LoadFile(NameFound); if (imgData != null) { using (MemoryStream mStream = new MemoryStream(imgData)) { using (DevIL.ImageImporter imImport = new DevIL.ImageImporter()) { SD.Bitmap returnx = LoadImage(imImport, mStream); if (foreceResize) { SD.Bitmap resized = new SD.Bitmap(returnx, new SD.Size(returnx.Width / 4, returnx.Height / 4)); return(resized); } else { return(returnx); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(new SD.Bitmap(width, height)); }
public Bitmap LoadImage(DevIL.ImageImporter ImImport, MemoryStream mStream, int width = 128, int height = 128) { try { Bitmap img2 = null; using (DevIL.Image IconImg = ImImport.LoadImageFromStream(mStream)) { IconImg.Bind(); using (var img = new Bitmap(IconImg.Width, IconImg.Height, PixelFormat.Format32bppArgb)) { Rectangle rect = new Rectangle(0, 0, IconImg.Width, IconImg.Height); BitmapData data = img.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, IconImg.Width, IconImg.Height, 1, DevIL.DataFormat.BGRA, DevIL.DataType.UnsignedByte, data.Scan0); img.UnlockBits(data); img2 = (Bitmap)img.Clone(); } } return(img2); } catch { return(new Bitmap(width, height)); } }