I’m trying to draw to an hdc in a C# program. Right now, I’m using Graphics g = Graphics.FromHdc(dc); and g.DrawImage(); to draw images.
This is ridiculously slow (100ms per draw), so I’d like to use Monogame to speed it up. Can monogame do this and if so, how??
Depending on what you’re trying to do, it might be easier to use SharpDX directly. Can you give some more information on your app? It’s hard to help with this little information.
Can monogame do this ?
if so. how?
Monogame is primarily for games. Its a lowlevel framework / api.
It’s Spritebatch.Draw method can draw thousands of images in a 60th second, using directx or opengl.
(essentially its a c# wrapper to dx gl with a bit extra added in more then just a api and less then a full engine)
The images are loaded thru the content pipeline typically at game initialization / load into textures on the graphics card.
however it might not be ideal for your needs.
It should be fine if you’re not constantly changing the bitmaps on a large scale. Loading a Texture2D from a System.Drawing.Bitmap is fast enough that unless it’s 2048^2 or greater you’re not going to notice it happening even on a potato.
What I’m trying to do is to read an images from a file (these are key frames in my renderer) and slowly zoom into them at 25 fps. The problem with system drawing is that I need to crop and resize images, sometimes multiple times, in 1/25th of a second. That doesn’t work. On my really fast computer, the best I could get was 10 fps.
Now I want to use monogame to draw to an hDC to do this. However, I’ve found something that may make this a lot more flexible. I can set a windows form’s parent to the HWND and I can set the windows form’s background to the image I want. The problem is: it still takes a lot of processing time using System Graphics.
I’d need Monogame to be able to zoom into one or more images at 25 FPS and convert this into a Bitmap with ~12ms left over to actually set the form background. If Monogame can do the processing at 60 FPS, it will be fast enough.
The problem is: it still takes a lot of processing time using System Graphics.
Yes because thats windows gdi its slooowww.
What I’m trying to do is to read an images from a file and slowly zoom into them at 25 fps. The problem with system drawing is that I need to crop and resize images,
What you would want to do in monogame is learn how to use a rendertarget create a camera and or learn how to use a pixel shader…
What I’m trying to do is to read an images from a file
(FILE IO) is the slowest texture operation no matter what you use.
Typically you load in as much as possible at the start from file you just load it from file to the videocard, and if need be as you go. Is this a image editing app your making ?
I can set a windows form’s parent to the HWND and I can set the windows form’s background to the image I want.
If your trying to get monogame into winforms ?
Im pretty sure its been done before, maybe someone who has done it can post a link to a tutorial for it.
There are however ui’s for monogame if you just wanted buttons and stuff inside a monogame window. Thus keeping your app far more cross-platfom that way.
As jjag said it might be easier to use sharp dx directly.
I’m trying to output images to draw onto my desktop background. There’s a neat article on code project about it. It basically allows me to set a windows form as my desktop background or a graphics object.
I want to read an image from a file every 5 minutes and resize that image to match each of my monitor’s resolutions. My current resizing speeds are fine for doing that every 5 minutes. What is slow is the zooming in part.
Ideally, I’d like Monogame to zoom into the image(s) and render it straight to the desktop, since I have the window handle. Or I can convert the image into a Bitmap and set it as the desktop background. Either way would work, but it has to be fast.