Convert Mogre.Image to System.Drawing.Bitmap

boyamer

23-04-2009 08:34:24

Is there any way to Convert Mogre.Image to System.Drawing.Bitmap and viceversa?

Thanks

Bostich

23-04-2009 21:10:14

Hi boyamer,

Image -> Bitmap and Texture -> Bitmap.
Other direction should be easy to find out ;)


/// <summary>
/// Converts an Ogre image to System.Drawing.Bitmap.
/// </summary>
/// <param name="img">Mogre.Image to convert</param>
/// <returns>System.Drawing.Bitmap</returns>
public static Bitmap MogreImageToBitmap(Mogre.Image img)
{
Bitmap bmp = new Bitmap((int)img.Width, (int)img.Height);
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Mogre.ColourValue color = img.GetColourAt(x, y, 0);
bmp.SetPixel(x, y, Color.FromArgb((int)color.GetAsARGB()));
}
}

return bmp;
}
/// <summary>
/// Converts an TexturePtr to an System.Drawing.Bitmap
/// </summary>
/// <param name="TexturePtr">Valid TexturePtr</param>
/// <param name="BitmapType">eg: PNG</param>
/// <param name="GroupName">the group where Mogre will find the image.</param>
/// <returns>System.Drawin.Bitmap</returns>
public static Bitmap TexturePtrToBitmap(Mogre.TexturePtr TexturePtr, String BitmapType, String GroupName)
{
Mogre.Image img = new Mogre.Image();
Mogre.DataStreamPtr dPtr = null;
String name = TexturePtr.Name;
if (TexturePtr.Name.StartsWith(GroupName))
name = TexturePtr.Name.Replace(GroupName, "");
if (name.Contains(".png"))
name = name.Replace(".png","");
try
{
dPtr = Mogre.ResourceGroupManager.Singleton.OpenResource(name + "." + BitmapType, GroupName);
}
catch
{
throw new Exception("Bitmap not found, or wrong image type.");
}
img.Load(dPtr, BitmapType);
return MogreImageToBitmap(img);
}

jmix90

28-04-2009 10:10:09

Hello,

A quick search should i give you the answer :P

Here is an article explaining step by step how to do it : http://blog.lexique-du-net.com/index.php?post/2009/03/25/Use-a-screenshot-of-a-WPF-visual-as-a-texture-in-Mogre.

+ + +