MonoGame/MonoGame · error · InvalidOperationException
Unexpected intermediate format: {intermediateFormat}
Error message
Unexpected intermediate format: {intermediateFormat} What it means
Thrown by GraphicsUtil's bitmap resize routine when the intermediate SurfaceFormat used for the resize does not match one of the three supported formats (Color, Rgba64, Vector4). The switch expression's default arm raises this InvalidOperationException with the offending format.
Source
Thrown at MonoGame.Framework.Content.Pipeline/Graphics/GraphicsUtil.cs:81
{
var errorMsg = Marshal.PtrToStringUTF8(err);
throw new InvalidContentException($"Bitmap resize failed: {errorMsg}");
}
}
finally
{
if (srcHandle.IsAllocated)
srcHandle.Free();
if (dstHandle.IsAllocated)
dstHandle.Free();
}
src = intermediateFormat switch
{
SurfaceFormat.Color => new PixelBitmapContent<Color>(newWidth, newHeight),
SurfaceFormat.Rgba64 => new PixelBitmapContent<Rgba64>(newWidth, newHeight),
SurfaceFormat.Vector4 => new PixelBitmapContent<Vector4>(newWidth, newHeight),
_ => throw new InvalidOperationException($"Unexpected intermediate format: {intermediateFormat}"),
};
src.SetPixelData(newBytes);
// Convert back to source type if required
if (format != intermediateFormat)
{
var s = (T)Activator.CreateInstance(bitmap.GetType(), [newWidth, newHeight])!;
BitmapContent.Copy(src, s);
src = s;
}
if (src is not T ret)
{
throw new Exception($"Invalid return type for bitmap, expected {typeof(T)}, got {src}");
}
return ret;
}View on GitHub (pinned to 1d71bbd0ff)
Solutions
- Convert the bitmap to an uncompressed PixelBitmapContent<Color> before resizing.
- Ensure the source TextureContent face is a supported uncompressed format.
- Extend the switch (if you control the codebase) to handle the additional intermediate format.
Example fix
// before GraphicsUtil.Resize(compressedTextureFace, newWidth, newHeight); // after content.ConvertBitmapType(typeof(PixelBitmapContent<Color>)); GraphicsUtil.Resize(content.Faces[0][0], newWidth, newHeight);
Defensive patterns
Strategy: validation
Validate before calling
var allowed = new[] { SurfaceFormat.Color, SurfaceFormat.Rgba64, SurfaceFormat.Vector4 };
var fmt = bitmap is BitmapContent bc ? /* resolve format */ SurfaceFormat.Color : throw new InvalidOperationException();
if (!allowed.Contains(fmt))
throw new InvalidOperationException($"Convert bitmap to an uncompressed Color/Rgba64/Vector4 format before resizing; got {fmt}."); Type guard
static bool IsResizableFormat(BitmapContent bitmap) =>
bitmap is PixelBitmapContent<Color>
or PixelBitmapContent<Rgba64>
or PixelBitmapContent<Vector4>; Try / catch
try { GraphicsUtil.Resize(bitmap, newWidth, newHeight); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Unexpected intermediate format"))
{
content.ConvertBitmapType(typeof(PixelBitmapContent<Color>));
GraphicsUtil.Resize(content.Faces[0][0], newWidth, newHeight);
} Prevention
- Decompress textures to PixelBitmapContent<Color> before any resize step.
- Avoid routing cube maps, DXT/BCx, or PVRTC content through the resize utility directly.
- Centralize a 'prepare for resize' helper that enforces supported formats.
When it happens
Trigger: The bitmap being resized reports an intermediate format outside {SurfaceFormat.Color, SurfaceFormat.Rgba64, SurfaceFormat.Vector4}. This intermediate format is derived from the source bitmap type during the resize pipeline.
Common situations: Passing a compressed (DXT/BCx/PVRTC/ETC) or exotic (HalfVector4, NormalizedByte4, etc.) bitmap content directly into the resize utility without first decompressing/converting it; a custom BitmapContent subclass returning an unexpected SurfaceFormat.
Related errors
- Could not retrieve surface format of source bitmap
- Could not retrieve surface format of destination bitmap
- DxtBitmapContent cannot compress format=[{format}]
- Bitmap resize failed: {errorMsg}
- Invalid return type for bitmap, expected {typeof(T)}, got {s
AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13).
Data as JSON: /api/errors/1f4425c627f683f9.
Report an issue: GitHub.