Hobbit9797
Hobbit9797

Reputation: 73

trying to load a bitmap, but xna want´s a Texture2D

I'm currently trying to load a simple bitmap using XNA but I get the following error:

Error loading "Maps\standard". File contains Microsoft.Xna.Framework.Graphics.Texture2D but trying to load as System.Drawing.Bitmap.

code:

public Bitmap map;

public void load(Game game, String image) {
    path = image; //path to image
    map = game.Content.Load<Bitmap>("Maps/"+path);
    sizeX = map.Width;
    sizeY = map.Height;
}

Upvotes: 1

Views: 921

Answers (2)

Hobbit9797
Hobbit9797

Reputation: 73

Now, I just use the C# standard

Bitmap bmp = (Bitmap)Bitmap.FromFile(path);

Upvotes: 0

George Duckett
George Duckett

Reputation: 32418

You want the below:

map = game.Content.Load<Texture2D>("Maps/"+path);

The way XNA works is that there is a content pipeline, which takes inputs (like your bitmap image) and produces outputs (the Texture2D), which is in a different format to the input.

XNA works with a Texture2D object when displaying images.

Upvotes: 1

Related Questions