Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3223030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:03:35+00:00 2026-05-17T16:03:35+00:00

I would like to do some processing of images in a WPF application. However,

  • 0

I would like to do some processing of images in a WPF application. However, I would like to modify the pixels of a BitmapSource in memory at runtime.

I’m currently managing to do this using ‘unsafe’ code against an old fashioned System.Drawing.Bitmap and it works a treat (lock a working area, fiddle with the pixels) job done. The approach is described in this post: http://blogs.msdn.com/b/ericgu/archive/2007/06/20/lost-column-2-unsafe-image-processing.aspx

To get this working in WPF I’m then creating a WPF BitmapSource using this approach:

    BitmapSource destination;
    IntPtr hBitmap = bitmap.GetHbitmap();
    BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
    destination = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
    destination.Freeze();
    return destination;

However, this creates a lot of copies in memory and I really want to get in there and fiddle with the underlying bits inside the BitmapSource just like EricGu showed in the Bitmap example. Is this possible?

I realise that PixelShaders can probably do this but this is an academic exercise involving multiple threads (which is supported when editing a bitmap in unsafe mode).

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:03:36+00:00Added an answer on May 17, 2026 at 4:03 pm

    I’ll tell you as much as I know.

    First you appear to already know about Freezing bitmaps before giving them back to the main thread. That’s a good start.

    I have once tried to reduce copying by deriving a new implementation from BitmapSource, and override the virtual functions that copy your data out of the bitmap. It worked but produced massive memory leaks. Never figured it out.

    You can also of course create a BitmapSource directly from an array of bytes (and lose overhead of the GDI bitmap). msdn docs

    Have you considered a WriteableBitmap? That was the WPF team’s response to the common complaint about all of the copying.

    Edit: MSDN says explicitly (in WritableBitmap.BackBuffer documentation) that it can be used from a background thread:

    You can pass the BackBuffer pointer to
    external components and other threads
    for processing, but if you do, you
    must provide you own thread
    coordination. In particular, you must
    ensure that the UI thread specifies
    changed areas by calling the
    AddDirtyRect method, and that the UI
    thread unlocks the buffer by calling
    the Unlock method.

    So if you let the UI thread aquire the lock and the pointer, you can let a worker thread write the pixels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently considering to develop an application for processing of images captured by
I would like to make frequently changes for the contact's image on the iPhone.
I have four videos that I would like to tile in a 2x2 fashion
This is probably a really simple question but... I would like to do a
...or... What evil in the depths of WPF have I awoken? I'm creating a
Hi I am a newbe to bash programming and need some help. I am
I've written an image processing program in MATLAB which makes heavy use of the
I have a loop to take in images from a high speed framegrabbger at
I am writing an application that takes an input image and looks in a
I have a live 16-bit gray-scale video stream that is pushed through a ring-buffer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.