1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public void AddFromFile(string File, string Name)
{
try
{
Il.ilInit();
Ilut.ilutRenderer(Ilut.ILUT_OPENGL);
Il.ilOriginFunc(Il.IL_ORIGIN_LOWER_LEFT);
Il.ilEnable(Il.IL_ORIGIN_SET);
Il.ilEnable(Il.IL_FILE_OVERWRITE);
Il.ilSetInteger(Il.IL_FORMAT_MODE, Il.IL_RGBA);
Il.ilEnable(Il.IL_FORMAT_SET);
int ImageId = ++this.LastOpenglIdUsed;
Il.ilGenImages(1, out ImageId);
Il.ilBindImage(ImageId);
if (!Ilut.ilutGLLoadImage(File))
{
MessageBox.Show("Could not open file, " + File + ", exiting.");
}
else
{
int Width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
int Height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
int Depth = Il.ilGetInteger(Il.IL_IMAGE_DEPTH);
int Bpp = Il.ilGetInteger(Il.IL_IMAGE_BITS_PER_PIXEL);
IntPtr Pixels = Il.ilGetData();
byte[] PixelArray = new byte[Width * Height * 4];
Marshal.Copy(Pixels, PixelArray, 0, Width * Height * 4);
this.Add(new PImage(this.LastOpenglIdUsed, Width, Height, PixelArray), Name);
Il.ilDeleteImages(1, ref ImageId);
}
}
catch
{
throw;
}
} |
Partager