Re: Save/Load DirectDraw.Surface
From: Fabian Schmied (REMOVETHISfabianDOTschmied_at_fhs-hagenbergDOTacDOTat)
Date: 03/21/04
- Next message: Jeff: "DirectDraw Surface Lock Method"
- Previous message: wyrd: "Device.IsUsingEventHandlers = false;"
- In reply to: Jeff: "Save/Load DirectDraw.Surface"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 21 Mar 2004 21:08:23 +0100
Jeff schrieb:
> What is the best way to save/load a DirectDraw.Surface to disk? I tried to
> use SurfaceLoader, however, it requires a Direct3D.Surface.
>
> Thanks for your help!
using System.Drawing;
void SaveSurface(string filename, Surface surface, int width, int height) {
SurfaceDescription desc = surface.SurfaceDescription;
using (Bitmap bitmap = new Bitmap(width, height)) {
using (Graphics graphics = Graphics.FromImage(bitmap) {
IntPtr hdc = graphics.GetHdc();
try {
surface.DrawToDc(hdc, new Rectangle(0, 0, width, height),
new Rectangle(0, 0, desc.Width, desc.Height));
}
finally {
graphics.ReleaseDc(hdc);
}
}
bitmap.Save(filename);
}
}
void LoadSurface(string filename, Surface surface) {
// similar
}
Surface LoadSurface(string filename, SurfaceDescription desc) {
// use the constructor that takes a string parameter
}
Fabian
- Next message: Jeff: "DirectDraw Surface Lock Method"
- Previous message: wyrd: "Device.IsUsingEventHandlers = false;"
- In reply to: Jeff: "Save/Load DirectDraw.Surface"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|