public void LoadFromPath(string texPath) { ImageReader loader = new ImageReader(); texPath = texPath.Replace(@"\\", @"/"); texPath = texPath.Replace(@"\", @"/"); path = texPath; using (System.IO.Stream stream = File.Open(texPath, FileMode.Open)) { StbSharp.Image image = loader.Read(stream, Stb.STBI_rgb_alpha); Width = image.Width; Height = image.Height; Tex = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, Tex); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, image.Data); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); GL.BindTexture(TextureTarget.Texture2D, 0); } }
public static void SetPixel(this Image img, int x, int y, Color color) { int offset = (y * img.Width + x) * img.Comp; img.Data[offset + 0] = color.R; img.Data[offset + 1] = color.G; img.Data[offset + 2] = color.B; img.Data[offset + 3] = color.A; }
public static Color GetPixel(this Image img, int x, int y) { int offset = (y * img.Width + x) * img.Comp; var red = img.Data[offset + 0]; var green = img.Data[offset + 1]; var blue = img.Data[offset + 2]; var alpha = img.Data[offset + 3]; return(Color.FromArgb(alpha, red, green, blue)); }