1
파일에서 직접 이미지를로드하는 방법을 찾았지만로드하는 이미지가 파란색 (원본은 초록색)입니다. 나는 그것이 나쁜 방식으로 저장되었다는 것을 알고 있었기 때문에 포토샵으로 저장했지만 아무것도 변경되지 않았습니다. 나는 내 프로그램이 나쁜 것 같아. 어떻게 변경하고 파일에서 이미지를로드하는 좋은 방법입니까? 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();