Hey,
I need to make a custom contentImporter in order to load textures greater than 4096^2 and split them into smaller pieces.
So I toke a look at the default TextureImporter and tried this:
public override Texture2DContent Import(string filename, ContentImporterContext context)
{
var output = new Texture2DContent();
var systemBitmap = new Bitmap(filename);
var height = systemBitmap.Height; var width = systemBitmap.Width;
// Force the input's pixelformat to ARGB32, so we can have a common pixel format to deal with. if (systemBitmap.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { var bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (var graphics = System.Drawing.Graphics.FromImage(bitmap)) { graphics.DrawImage(systemBitmap, 0, 0, width, height); } systemBitmap = bitmap; }
PixelBitmapContent<Byte4> bcontent = new PixelBitmapContent<Byte4>(width, height); bcontent.SetPixelData(ImageToByte(systemBitmap));
output.Faces.Add(bcontent); systemBitmap.Dispose(); return output; } private static byte[] ImageToByte(Image img) { byte[] byteArray = new byte[0]; using (MemoryStream stream = new MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); } return byteArray; }
I get this error:
Error 1 Building content threw ArgumentException: The sourceData array has length 5341738, but bitmap pixel data size should be 17068000.
I’ve tried different types in PixelBitmapContent to make sure that wasn’t the problem.
I would appreciate any advice!
Thank you.
edit: this is just for reading the texture itself, the split into smaller pieces would go in the ContentProcessor