public Texture Load(IResource resource, ImageType imageType, ImageLoaderParameters loaderParams) { m_imageState.AbsoluteFormat = DataFormat.RGBA; m_imageState.AbsoluteDataType = DataType.UnsignedByte; m_imageState.AbsoluteOrigin = OriginLocation.UpperLeft; ApplyImageStates(); using (Stream stream = resource.OpenStream()) { DevIL.Image image = m_importer.Load(stream, imageType); return(CreateTexture(new ManagedImage(image))); } }
public static System.Drawing.Image LoadImageFromStream(Stream stream) { ImageImporter importer = new ImageImporter(); DevIL.Image img = importer.LoadImageFromStream(stream); DevIL.Unmanaged.ImageInfo imageInfo = img.GetImageInfo(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageInfo.Width, imageInfo.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(0, 0, imageInfo.Width, imageInfo.Height); System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, imageInfo.Width, imageInfo.Height, 1, DataFormat.BGRA, DevIL.DataType.UnsignedByte, bitmapData.Scan0); bitmap.UnlockBits(bitmapData); return((System.Drawing.Image)bitmap); }
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)); } }
public bool saveImage(string fileName) { try { string txtFile = fileName.Replace(".dds", ".txt"); string txtFilepng = fileName.Replace(".dds", ".png"); try { File.Delete(fileName); } catch { } GeneralIcon[] array = currentIcons.Values.ToArray(); StringBuilder sb = new StringBuilder(); sb.AppendLine(w.ToString()); sb.AppendLine(h.ToString()); int rrow = array.Length / cols; sb.AppendLine(rrow.ToString()); sb.AppendLine(cols.ToString()); int imageWidth = w * cols; using (Bitmap img = new Bitmap(imageWidth, imageWidth, PixelFormat.Format32bppArgb)) { using (Graphics graphics = Graphics.FromImage(img)) { int x, y = 0; for (int i = 0; i < array.Length; i++) { GeneralIcon icon = array[i]; y = i / cols; x = i - y * cols; x = x * w; y = y * h; graphics.DrawImage(icon.icon, x, y); sb.AppendLine(icon.name); } } using (DevIL.ImageImporter ImImport = new DevIL.ImageImporter()) { using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); using (DevIL.Image IconImg = ImImport.LoadImageFromStream(new MemoryStream(ms.ToArray()))) { IconImg.Bind(); ImageExporter exporter = new ImageExporter(); exporter.SaveImage(IconImg, ImageType.Dds, fileName); } } } File.WriteAllText(txtFile, sb.ToString(), Encoding.GetEncoding("GBK")); } Remake(); return(true); } catch { return(false); } }