Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 1500x1500 image at 30fps on wpf

1500x1500 image at 30fps on wpf

Scheduled Pinned Locked Moved C#
csharpwpfcomquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andreoli Carlo
    wrote on last edited by
    #1

    Hello, i'm moving my actual winform based application to WPF. My application acquire 1500x1500 8bit depth images at 30 frame per second. In winform i was used to BitBlt my images to a panel handle and that work fine. In wpf i tried two ways:

    // on every frame:
    int stride = img_w * ((PixelFormats.Gray8.BitsPerPixel + 7) / 8);
    bmpSource = BitmapSource.Create(img_w, img_h, 96, 96, PixelFormats.Gray8, null, my_arrb_8bit, stride);

    this.Image1.Source = bmpSource;

    but this is too slow...then i try

    // on every frame:
    int max = PixelFormats.Rgb24.BitsPerPixel;
    uint count = (uint)(img_w * img_h * PixelFormats.Rgb24.BitsPerPixel / 8);
    IntPtr section = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, FileMapProtection.PageReadWrite, 0, count, null);
    IntPtr map = MapViewOfFile(section, FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)count);

    System.Runtime.InteropServices.Marshal.Copy(my_arrb_24bit, 0, map, (int)count);
    my_ibs = System.Windows.Interop.Imaging.CreateBitmapSourceFromMemorySection(
    section,
    (int)img_w,
    (int)img_h,
    PixelFormats.Rgb24,
    (int)(img_w * PixelFormats.Rgb24.BitsPerPixel / 8), 0) as System.Windows.Interop.InteropBitmap;
    this.Image1.Source = my_ibs;

    this is faster than the first solution, but still i can't manage to reach 30fps....am i doing something wrong? any suggestion?

    P 1 Reply Last reply
    0
    • A Andreoli Carlo

      Hello, i'm moving my actual winform based application to WPF. My application acquire 1500x1500 8bit depth images at 30 frame per second. In winform i was used to BitBlt my images to a panel handle and that work fine. In wpf i tried two ways:

      // on every frame:
      int stride = img_w * ((PixelFormats.Gray8.BitsPerPixel + 7) / 8);
      bmpSource = BitmapSource.Create(img_w, img_h, 96, 96, PixelFormats.Gray8, null, my_arrb_8bit, stride);

      this.Image1.Source = bmpSource;

      but this is too slow...then i try

      // on every frame:
      int max = PixelFormats.Rgb24.BitsPerPixel;
      uint count = (uint)(img_w * img_h * PixelFormats.Rgb24.BitsPerPixel / 8);
      IntPtr section = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, FileMapProtection.PageReadWrite, 0, count, null);
      IntPtr map = MapViewOfFile(section, FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)count);

      System.Runtime.InteropServices.Marshal.Copy(my_arrb_24bit, 0, map, (int)count);
      my_ibs = System.Windows.Interop.Imaging.CreateBitmapSourceFromMemorySection(
      section,
      (int)img_w,
      (int)img_h,
      PixelFormats.Rgb24,
      (int)(img_w * PixelFormats.Rgb24.BitsPerPixel / 8), 0) as System.Windows.Interop.InteropBitmap;
      this.Image1.Source = my_ibs;

      this is faster than the first solution, but still i can't manage to reach 30fps....am i doing something wrong? any suggestion?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Off the top of my head, I'd suspect that the issue that you are hitting is because you are creating new BitmapSource elements each time. Basically, a WPF Bitmap is an immutable object - normally this is a good thing - but in the case where you want to keep changing a source, I'd suggest that you should look at a WriteableBitmap instead. This will give you some ability to mimic the BitBlt functionality.

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        Off the top of my head, I'd suspect that the issue that you are hitting is because you are creating new BitmapSource elements each time. Basically, a WPF Bitmap is an immutable object - normally this is a good thing - but in the case where you want to keep changing a source, I'd suggest that you should look at a WriteableBitmap instead. This will give you some ability to mimic the BitBlt functionality.

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        A Offline
        A Offline
        Andreoli Carlo
        wrote on last edited by
        #3

        On a first try using

        writeableBitmap.Lock();
        unsafe {
        Marshal.Copy(my_arrb_8bit
        , 0
        , writeableBitmap.BackBuffer
        , img_w * img_h);
        }

        // Specify the area of the bitmap that changed.
        writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, img_w, img_h));

        // Release the back buffer and make it available for display.
        writeableBitmap.Unlock();

        seems to start working not yet at 30fps but almost there...thank you very much :)

        P 1 Reply Last reply
        0
        • A Andreoli Carlo

          On a first try using

          writeableBitmap.Lock();
          unsafe {
          Marshal.Copy(my_arrb_8bit
          , 0
          , writeableBitmap.BackBuffer
          , img_w * img_h);
          }

          // Specify the area of the bitmap that changed.
          writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, img_w, img_h));

          // Release the back buffer and make it available for display.
          writeableBitmap.Unlock();

          seems to start working not yet at 30fps but almost there...thank you very much :)

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          You're welcome.

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups