我想创建一个应用程序,在其中创建一个位图,然后从中取出一些变量并从中创建一个Texture2D。这是我有:如何访问C#XNA中位图的宽度和高度?
public Bitmap getBitmap()
{
if (!panelVideoPreview.IsDisposed)
{
Bitmap b = new Bitmap(panelVideoPreview.Width, panelVideoPreview.Height, PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(b);
Rectangle videoRect = panelVideoPreview.Bounds;
panelVideoPreview.DrawToBitmap(b, videoRect);
b.Dispose();
return b;
}
else
{
Bitmap b = new Bitmap(panelVideoPreview.Width, panelVideoPreview.Height);
return b;
}
}
然后我尝试从它创建一个纹理:
Texture2D tex = new Texture2D(gDevice, (int)bit.Width, (int)bit.Height);
这是我的错误,我得到这个:
System.ArgumentException未处理 Message =参数无效。 D:\ Dropbox \ School \ Project中的GPUParticlesTexture.createVelocityMapBitmap(GraphicsDevice gDevice,位图位,单精度)的System.Drawing.Image.get_Width() FUN \ Code \XNA \ GPUParticles \ GPUParticles \ GPUParticles \ VelocityTexture.cs:第16行 GPUParticles.Game1.camInterval_Tick的.cs:线302 在System.Windows.Forms.Timer.OnTick(EventArgs的) 在System.Windows.Forms.Timer.TimerNativeWindow.WndProc(消息&米) 在System.Windows.Forms.NativeWindow.DebuggableCallback( IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG & MSG) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr的dwComponentID,的Int32原因,的Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.Run (Form mainForm) at Microsoft.Xna.Framework.WindowsGameHost.Run() at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun) at Microsoft.Xna.Framework.Game.Run() 在GPUParticles.Program.Main(字串[] args)在d:\ Dropbox的\学校\项目FUN \代码\ XNA \ GPUParticles \ GPUParticles \ GPUParticles \的Program.cs:行15 的InnerException:
你不是从创建它的纹理,你只是试图创建相同的宽度和高度的位图的一个空的纹理。你需要在你的解决方案中使用位图吗?因为如果你只需要用自定义数据创建纹理,我可以提出一个解决方案。 – neeKo 2012-04-22 23:35:54