Download image in .Net standard

I'm trying to load a png file (other formats are an option) to render as textures in OpenTk targeting a .netstandard 1.4 project , which does not support the System.Drawing libraries.

Every OpenTk example I can find depends on the System.Drawing.Bitmap class.

Here is an example of the type of method I want to create without the System.Drawing libraries, from the texture class of this 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);
    }

      

What is the other way to download images and create them for use with OpenTk?

+3


source to share


1 answer


Intermediate parameters for the transition of OpenTK to .NETStandard2.0



+2


source







All Articles