我想創建一個應用程序,在其中創建一個位圖,然後從中取出一些變量並從中創建一個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