![]() |
|
RENDER TO BITMAP WORKAROUND - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab4d.SharpEngine (https://forum.ab4d.com/forumdisplay.php?fid=12) +--- Thread: RENDER TO BITMAP WORKAROUND (/showthread.php?tid=4479) |
RENDER TO BITMAP WORKAROUND - BiMMate - 03-06-2025 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? RE: RENDER TO BITMAP WORKAROUND - BiMMate - 03-06-2025 I guess the issue is related to the fact that the newly created SceneView is not in the visual tree of controls, so... Is there a way I can render a snapshot in this situation? RE: RENDER TO BITMAP WORKAROUND - abenedik - 03-06-2025 If the SharpEngineSceneView is not shown, then its size is not defined. If you want to render it, you need to manually set its size by setting Width and Height properties before calling RenderToBitmap method. Even better for your use case is to create the SceneView objects (generic SharpEngine objects) instead of SharpEnginSceneView object (Avalonia specific). For example: Code: var sceneView = new SceneView(_scene, "SceneView");RE: RENDER TO BITMAP WORKAROUND - BiMMate - 03-06-2025 Thanks a lot That did the trick |