1
ファイルから直接画像をロードする方法が見つかりましたが、ロードする画像は青色です(元は緑色です)。私は悪いところで救われたので、Photoshopで保存しましたが、何も変わりませんでした。私のプログラムは悪いと思う。どのように私はそれを変更することができますし、ファイルから画像を読み込むために良い方法ですか? Texture2D方法に ビットマップ:XNAとファイルから画像をロード
public static Texture2D GetTexture2DFromBitmap(GraphicsDevice device, Bitmap bitmap)
{
Texture2D tex = new Texture2D(device, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
int bufferSize = data.Height * data.Stride;
byte[] bytes = new byte[bufferSize];
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
tex.SetData(bytes);
bitmap.UnlockBits(data);
return tex;
}
画像読み込み中ライン:
backgroundTexture = Tools.GetTexture2DFromBitmap(device, (System.Drawing.Bitmap)System.Drawing.Image.FromFile(@"1.bmp", false));
Drawningテクスチャ方法:
spriteBatch.Begin();
Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
spriteBatch.Draw(backgroundTexture, screenRectangle, Color.White);
spriteBatch.End();