static public Texture LoadFromFile(string filePath) { ImageImporter importer = new ImageImporter(); ImageExporter exporter = new ImageExporter(); Image image; image = importer.LoadImage(filePath); if (Path.GetExtension(filePath) != ".tga" && Path.GetExtension(filePath) != ".png") { if (!File.Exists(filePath.Replace(Path.GetExtension(filePath), ".tga"))) { exporter.SaveImage(image, ImageType.Tga, filePath.Replace(Path.GetExtension(filePath), ".tga")); } image = importer.LoadImage(filePath.Replace(Path.GetExtension(filePath), ".tga")); } //image.Bind(); //var info = DevIL.Unmanaged.IL.GetImageInfo(); //var bitmap = new System.Drawing.Bitmap(info.Width, info.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var rect = new System.Drawing.Rectangle(0, 0, info.Width, info.Height); //var data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, info.Width, info.Height, info.Depth, DataFormat.BGRA, DataType.UnsignedByte); //bitmap.UnlockBits(data); //var converter = new System.Drawing.ImageConverter(); //var test = converter.ConvertTo(bitmap, typeof(byte[])); //var raw = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); return(new Texture(image)); }
private void _loadBitmap(uint sideID) { // Import the image ImageImporter _importer = new ImageImporter(); _images[sideID] = _importer.LoadImage(_textures[sideID]); // Dispose the importer _importer.Dispose(); // Bind the impi]orted Image _images[sideID].Bind(); // Generate bitmap from image Bitmap BitmapImage = _images[sideID].ToBitmap(); // Must be Format32bppArgb file format, so convert it if it isn't in that format BitmapData bitmapData = BitmapImage.LockBits(new System.Drawing.Rectangle(0, 0, BitmapImage.Width, BitmapImage.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(_types[sideID], 0, PixelInternalFormat.Rgba8, BitmapImage.Width, BitmapImage.Height, 0, Core.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0); GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, TextureParameter.Linear); GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, TextureParameter.Linear); GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, TextureParameter.ClampToEdge); GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, TextureParameter.ClampToEdge); GL.TexParameteri(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, TextureParameter.ClampToEdge); // Dispose bitmap (it will not longer be used) BitmapImage.UnlockBits(bitmapData); BitmapImage.Dispose(); // Make sure the Image will not be modified from the outside _images[sideID].Unbind(); }
static public List <Texture> LoadFromFile(string rootPath, string filePath) { ImageImporter importer = new ImageImporter(); ImageExporter exporter = new ImageExporter(); Image image; List <Texture> textures = new List <Texture>(); string[] fps = filePath.Split('*'); string fp; for (int i = 0; i < fps.Length; i++) { fp = rootPath + fps[i]; image = importer.LoadImage(fp); if (Path.GetExtension(fp) != ".tga" && Path.GetExtension(fp) != ".png") { if (!File.Exists(fp.Replace(Path.GetExtension(fp), ".tga"))) { exporter.SaveImage(image, ImageType.Tga, fp.Replace(Path.GetExtension(fp), ".tga")); } image = importer.LoadImage(fp.Replace(Path.GetExtension(fp), ".tga")); } //image.Bind(); //var info = DevIL.Unmanaged.IL.GetImageInfo(); //var bitmap = new System.Drawing.Bitmap(info.Width, info.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var rect = new System.Drawing.Rectangle(0, 0, info.Width, info.Height); //var data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //DevIL.Unmanaged.IL.CopyPixels(0, 0, 0, info.Width, info.Height, info.Depth, DataFormat.BGRA, DataType.UnsignedByte); //bitmap.UnlockBits(data); //var converter = new System.Drawing.ImageConverter(); //var test = converter.ConvertTo(bitmap, typeof(byte[])); //var raw = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); textures.Add(new Texture(image, fp)); } return(textures); }
/// <summary> /// Load an image and use it as a cursor. /// </summary> /// <param name="image">The path to the image.</param> public void FromImage(string image) { ImageImporter importer = new ImageImporter(); Image img = importer.LoadImage(image); importer.Dispose(); img.Bind(); _image.Width = img.Width; _image.Height = img.Height; _image.Pixels = IL.CopyPixels(0, 0, 0, img.Width, img.Height, 1, DataFormat.BGRA, DataType.UnsignedByte); img.Unbind(); img.Dispose(); _cursor = GLFW.GLFW.CreateCursor(_image, HotX, HotY); }
/// <summary> /// Load and create a new image. /// </summary> /// <param name="file">The image file.</param> /// <param name="offsetX">The X offset from which pixels will be read.</param> /// <param name="offsetY">The Y offset from which pixels will be read.</param> /// <param name="offsetZ">The Z offset from which pixels will be read.</param> /// <param name="width">The width of the loaded.</param> /// <param name="height">The height of the loaded.</param> /// <param name="depth">The depth.</param> /// <param name="format">The format in which pixels will be read.</param> /// <param name="type">The type of data in which pixels will be read.</param> public Image(string file, int offsetX = 0, int offsetY = 0, int offsetZ = 0, int width = 0, int height = 0, int depth = 1, DataFormat format = DataFormat.BGRA, DataType type = DataType.UnsignedByte) { ImageImporter importer = new ImageImporter(); _i = importer.LoadImage(file); // Dispose the importer importer.Dispose(); // Populate fields _x = offsetX; _y = offsetY; _z = offsetZ; _d = depth; _f = format; _t = type; // Register this resource as a disposable resource ResourcesManager.AddDisposableResource(this); }