[Texture2D] Texture2D에 일정역역만 복사하기
원본 텍스쳐에서 일부분만 그리는 방법에서 기초적인 방법은 Draw 에서
그릴 영역을 지정하는것인데 리소스 낭비가 발생할수 있어서
아에 처음부터 영역을 정하고 들어가도록 하는 방법이다.
Created with colorer-take5 library. Type 'csharp' //http://scripter.egloos.com //원본 이미지 텍스쳐 Texture2D targetTx; //복제할 이미지 텍스쳐 Texture2D copyTx; protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); //원본 이미지를 가져��다 targetTx = Texture2D.FromFile(GraphicsDevice,@"c:\a.jpg"); //복제할 이미지를 만든다. copyTx = CloneImage(targetTx, 0, 0, 200, 200); } //복제 메소드 :: 매개변��로는 원본이미지,좌표,크기 이다. public Texture2D CloneImage(Texture2D image, int x, int y, int w, int h) { //면적을 만든다. Rectangle srcRect = new Rectangle(x, y, w, h); //면적만큼�� 바이트 배열을 생성한다 // *4 인이유는 ���� 정���� 메모리 크기가 4바이트이기때문은 상식 byte[] data = new byte[srcRect.Width * srcRect.Height * 4]; //원본이미지에서 면적만큼 가져와 바이트배열에 저장한다. image.GetData(0, srcRect, data, 0, data.Length); //새로운 텍스쳐를 생성한다. //주��할점은 TextureFormat을 원본이미지�� Format과 같게해야 된다. Texture2D result = new ResolveTexture2D(this.GraphicsDevice, srcRect.Width, srcRect.Height, 0, image.Format); //데이터를 채워주고.. result.SetData(data); //����한다. return result; }참고 :: http://xna.omgsoft.com.cn/education/graphicex_class.aspx
중요한점은 복제될 Texture2D의 Format 과 원본 Texture2D 의 Format 이 일치해야 되더라
'XNA' 카테고리의 다른 글
[찰스페졸드] windows phone7 책 완성판 (53) | 2010.12.06 |
---|---|
XNA 초간단 그림 붙이기 (45) | 2010.12.04 |
[Texture2D] Texture2D에 일정역역만 복사하기 (40) | 2010.12.04 |
[XNA , Texture2D] Texture2D from Bitmap (very Simple) (276) | 2010.12.04 |
하나의 BasicEffect 에 여러 텍스쳐 그리기 (5) | 2010.12.04 |
[XNA Game Programing Chapter5 converting XNA3.1] (46) | 2010.12.04 |
XNA
2010.12.04 02:30