Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created August 11, 2011 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/1138924 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1138924 to your computer and use it in GitHub Desktop.
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
private Image OpenImage(String filename)
{
byte[] image = File.ReadAllBytes(filename);
Stream stream = new MemoryStream();
stream.Write(image,0,image.Length);
stream.Position = 0;
stream.SetLength(image.Length);
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthStencil = true;
Device device = new Device(0,
DeviceType.Hardware,
this.imagePanel,
CreateFlags.SoftwareVertexProcessing,
presentParams
);
BaseTexture texture = TextureLoader.FromStream(device,stream);
GraphicsStream gStream = TextureLoader.SaveToStream(ImageFileFormat.Bmp,texture);
return new Bitmap(gStream);
}
private void TargaPictureBoxForm_Load(object sender, EventArgs e)
{
Image i = OpenImage("flower.tga");
displayPictureBox.Image = i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment