Loading png, jpg etc directly

Isn’t it possible anymore to load png files directly as content?
Is there a workaround?

I am using pngs exclusively, so it’s working for sure

I load the .png in my Content.mgcb and then access it via

SandTexture = content.Load<Texture2D>("Art/Sand_5_diffuse");  

Edit: Ah sorry i think i misread.
Is the question whether you can load without the MG Content Builder? Why?

I like to load png’s directly aswell as I’m using TexturePacker to create sprite atlases and don’t want to run them through MGCB every time I change something. Also I like png compression and other team members can easily edit them without having to use MGCB themselves.

I use this code on Windows:

FileStream fileStream = new FileStream("Content/sprites/sprite_atlas.png", FileMode.Open):
Texture2D spriteAtlas = Texture2D.FromStream(graphicsDevice, fileStream);

The ability to load PNG and JPG directly through the ContentManager has now been removed in the develop branch. ContentManager now only loads .xnb files that have been produced by the content pipeline (XNA content pipeline or MonoGame content pipeline).

PNG and JPG images can still be loaded directly through Texture2D.FromStream as described above.

Is it possible again to load textures directly or is this a bug?

Loading textures through ContentManager requires that they be processed by the content build pipeline. PNG and JPG images can be loaded at runtime through Texture2D.FromStream(Stream), as described earlier in this thread.

Yes I know that, but I couldn’t load PNG/JPG directly with MG 3.5 but with 3.5.1 it’s possible again, Thats why I asked is this wanted or unwanted before I change my whole project again.

This needs clarification. Load PNG and JPG directly through ContentManager or through Texture2D.FromStream? Loading PNG and JPG directly through ContentManager was available in 3.5 and 3.5.1, but has since been removed (in current develop branch and in the next release). It was never removed and reinstated.

  1. Open the Monogame Pipeline Tool!
  2. Under Project, select Content!
  3. Go to Edit -> Add -> Existing Item!

If you added all your content allready in the folder Content in your Monogame project these should now be visible, as this is the official way to add ressources!

This is not necessary, just browse to your directory, but for the sake of quickness, add them beforehand and you are set!

  1. Now, click the Build icon, its the gear icon on the right!

You should have no errors whatsoever and your png files should be part of the list of things that have been built, if not, rebuild, or clean and then build again!

  1. Done!

I dont know if this is still needed, but for the sake of completion and for others that stumble upon this, here you go!

In your Game1 class:

protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);
this.Content.Load(“YOUR_TEXTURE_NAME_HERE”); // without the .png or .jpeg, or whatever yours ends with!

this still works for me on 3.8.1 with net6.0
Thanks! :slight_smile: