Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RENDER TO BITMAP WORKAROUND
#1
Hello

I have an scenario where the Scene exists but the SceneView may not
The Scene contains everything needed like 3D geometry or lights but the camera

I then need to render a snapshot

I know I can easily do this in the SceneView control, but this control may not exists at the time I request the screenshoot

So, in the Scene I am creating a new SceneView, add this instance to it, add the camera and then render to bitmap, but I am getting null

As library is protected, I cannot step into the RenderToBitmap method to undersrand why is this happening

This is so far my method defined in a custom class that inherits from Ab4d.SharpEngine.Scene:

private bool TakeScreenShot(ref WriteableBitmap? writeableBitmap)
{
    var sceneView = new SharpEngineSceneView(this, "SceneView")
    {
      BackgroundColor = Avalonia.Media.Colors.Transparent
    };
    var targetPositionCamera = new TargetPositionCamera
    {
      Attitude = this.dataContext.LastCameraAttitude ?? -30f,
      Distance = this.dataContext.LastCameraDistance ?? 500f,
      FieldOfView = this.dataContext.LastCameraFieldOfView.HasValue ? (float)this.dataContext.LastCameraFieldOfView.Value : 45f,
      Heading = this.dataContext.LastCameraHeading ?? -40f,
      IsAutomaticFarPlaneDistanceCalculation = false,
      IsAutomaticNearPlaneDistanceCalculation = false,
      MaxFarPlaneDistance = float.NaN,
      MinNearPlaneDistance = 0f,
      ProjectionType = this.dataContext.IsPerspectiveProjection ? ProjectionTypes.Perspective : ProjectionTypes.Orthographic,
      ShowCameraLight = ShowCameraLightType.Never,
      TargetPosition = this.dataContext.LastCameraTargetPosition ?? new Vector3(0f, 0f, 0f),
      ViewWidth = 500
    };
    sceneView.
SceneView.Camera = targetPositionCamera;

    return sceneView.RenderToBitmap(ref writeableBitmap);
}


Any tip why I'm not getting what I need?
  


Messages In This Thread
RENDER TO BITMAP WORKAROUND - by BiMMate - 03-06-2025, 11:59 AM
RE: RENDER TO BITMAP WORKAROUND - by BiMMate - 03-06-2025, 12:03 PM
RE: RENDER TO BITMAP WORKAROUND - by abenedik - 03-06-2025, 12:07 PM
RE: RENDER TO BITMAP WORKAROUND - by BiMMate - 03-06-2025, 01:01 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)