在 .Net Standard 中加载图像

Kel*_*all 4 c# system.drawing image opentk .net-standard

我正在尝试加载一个 png 文件(其他格式是一个选项),以便在面向 .netstandard 1.4 的项目中的 OpenTk 中渲染为纹理,该项目不支持 System.Drawing 库。

我可以为此找到的每个 OpenTk 示例都取决于 System.Drawing.Bitmap 类。

这是我想在没有 System.Drawing 库的情况下创建的那种方法的示例,来自此Jitter Physics OpenGL Demo的纹理类

    void CreateFromBitmap(System.Drawing.Bitmap image)
    {
        image.RotateFlip(RotateFlipType.RotateNoneFlipY);

        GL.GenTextures(1, out name);
        GL.BindTexture(TextureTarget.Texture2D, name);

        // set pixel unpacking mode
        GL.PixelStore(PixelStoreParameter.UnpackSwapBytes, 0);
        GL.PixelStore(PixelStoreParameter.PackRowLength, 0);
        GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
        GL.PixelStore(PixelStoreParameter.UnpackSkipRows, 0);
        GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, 0);

        BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
            ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        // Requieres OpenGL >= 1.4
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1); // 1 = True
        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                      OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

        image.UnlockBits(data);

        // set texture parameters - will these also be bound to the texture???
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)All.Repeat);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)All.Repeat);

        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.LinearMipmapLinear);

        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.Decal);

        image = null;
        // Unbind
        GL.BindTexture(TextureTarget.Texture2D, 0);
    }
Run Code Online (Sandbox Code Playgroud)

加载图像并格式化它们以与 OpenTk 一起使用的另一种方法是什么?

Jim*_*EOW 5

将 OpenTK 过渡到 .NETStandard2.0 的中间选项