Unknown Error,直接出来那种
...exe has encountered a problem and needs to close. We are sorry for the inconvenience.
对话框。
没有错误消息。
...exe has encountered a problem and needs to close. We are sorry for the inconvenience.
对话框。
没有错误消息。
随便在某个D3D程序中加入
Bitmap bmp = new Bitmap(400, 300);
Graphics graphics = Graphics.FromImage(bmp);
graphics.DrawLine(new Pen(Color.Red, 5), 0, 0, 400, 300);
texture = new Texture(device, bmp, Usage.Dynamic, Pool.Default);
代码就会出错。
使用
texture = Texture.Texture.FromBitmap(device, bmp, 0, Pool.Default);
也会出同样的错。
大家帮忙看看是为什么啊。我现在只能使用将Image写入MemoryStream,然后再用Textureloader.FromStream导入,
但是这样作的效率很低,程序有明显的停顿。
请问大家怎么能解决这个问题啊。
拉兄弟一把吧。兄弟我郁闷死了。
你当然可以:
texture =new Texture(dev, bmp,0, Pool.Managed);Texture.FromBitmap在内部就是调用了上面这个构造函数。如果你的代码依然无法正常运行,那检查你代码的其他部分,比如device是如何创建的,还有你用什么ide?
{
Texture texture = null;
using (MemoryStream mmStream = new MemoryStream())
{
bmp.Save(mmStream, ImageFormat.Jpeg);
mmStream.Seek(0, SeekOrigin.Begin);
texture = TextureLoader.FromStream(device, mmStream);
mmStream.Close();
}
return texture;
}
我现在使用的代码时这样的,可以正常运行,但是速度慢,而且太愚蠢了。
但是感觉基本可以证明bmp和device都是没有问题的。当我把代码改成:
private static Texture GetTexture(Bitmap bmp)
{
Texture texture = null;
texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
return texture;
}
运行时出现 System.NullReferenceException 这我就搞不清楚了,而且我跟踪device和bmp都不是空的。我不明白为什么会是这个异常。还有我使用的bmp是Bitmap类的成员这个有没有问题?
看了几个代码好像都是从resource里面load的bitmap.
Bitmap bmp = new Bitmap("c:\\1.jpg");
Texture texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
这回出现的是Invalide Call Exception,
在这里面应该device的创建肯定没有问题。
你只需这样就能够正确的创建texture么?
会不会是我的显卡的问题?
我现在这个应用要频繁的更改Texture上面的图,
比如在原来的Bitmap上面DrawString DrawImage DrawRectangle之类的事情,如果我没次操作之后都
using (MemoryStream mmStream = new MemoryStream())
{
bmp.Save(mmStream, ImageFormat.Jpeg);
mmStream.Seek(0, SeekOrigin.Begin);
texture = TextureLoader.FromStream(device, mmStream);
mmStream.Close();
}
这样速度太慢了,每次都要大概占去400ms左右的时间.
大家有什么办法提速么?