MilleVisionNotes

This site focuses on practical examples of controlling Basler industrial cameras
using the pylon SDK and C#, based on real-world development experience.

タグ: Basler

  • How to Capture a Single Image from Basler ace Camera using pylon SDK in C#


    How to Capture a Single Image from Basler ace Camera using pylon SDK in C#

    Basler industrial cameras can be controlled easily using the pylon Camera Software Suite.
    In this article, I’ll show you how to connect to a camera, grab a single frame, convert it to a BitmapSource, and save it as a .bmp file—all using C# and .NET 8.

    When I first started working with Basler cameras in a .NET environment, I found very few practical code examples.
    This guide is based on tested code from my own applications.

    This article covers:

    • Connecting to a camera
    • Capturing one frame (Snap)
    • Converting to BitmapSource (WPF-friendly)
    • Saving the image as .bmp

    ⚠️ Important Notice

    This article demonstrates how to develop custom applications using the Basler pylon Camera Software Suite SDK.

    • The content here is based on my own testing and implementation
    • It is not endorsed by Basler AG
    • The SDK itself is not redistributed here (no DLLs, headers, etc.)

    To use the SDK, download it directly from Basler’s official website:

    🔗 pylon SDK download
    https://www.baslerweb.com/en/products/software/basler-pylon-camera-software-suite/

    Make sure to review the EULA, especially if using the SDK in commercial or high-risk environments:
    https://www.baslerweb.com/en/service/eula/

    The sample code in this article is provided strictly for learning and reference. Use it at your own responsibility.


    ✔ Environment

    ItemDetails
    SDKBasler pylon Camera Software Suite
    LanguageC# (.NET 8.0 — Windows)
    CameraBasler acA2500-14gm
    OSWindows 10 / 11

    1. Connecting to the Camera

    First, create a simple wrapper class for managing the connection.
    You can connect to the first available camera or use a specified camera name (as shown in Basler pylon Viewer).


    2. Capturing a Single Image

    The simplest way to grab one frame is by calling GrabOne() through the Stream Grabber.


    3. Converting to BitmapSource (for WPF)

    IGrabResult cannot be displayed directly in WPF.
    We convert it to a BitmapSource using PixelDataConverter.

    Supports:

    • RGB8packed
    • BGR8packed
    • Mono8 (default fallback)

    4. Saving the Image as .bmp

    A simple helper method using BmpBitmapEncoder:


    5. Example Test Code

    You can easily test the entire pipeline (grab → convert → save) using the following:


    ✔ Output Example

    The captured image will be saved as:SaveBitmapTest.bmp

    Example output:

    (Image from the original article)


    ✨ Conclusion

    Although official documentation covers the basics, hands-on .NET examples for pylon are still relatively rare.
    Fortunately, pylon’s .NET API is clean and integrates smoothly with Windows desktop applications such as WPF.