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

  • SEARCH
  • Home
  • 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 7440139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:48:23+00:00 2026-05-29T10:48:23+00:00

I am buliding a GUI around an algorithm. For this purpose I have a

  • 0

I am buliding a GUI around an algorithm. For this purpose I have a Window component which contains a Image component inside it.

The content inside the Image component (imgHolder) is given by a BitmapImage object (_image), which for the purpose of this example is initialized as such:

_image = new BitmapImage();
_image.BeginInit();
_image.CacheOption = BitmapCacheOption.OnLoad;
_image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
_image.UriSource = new Uri("c:\\a1.bmp");
_image.EndInit();

imgHolder.Source = _image;

The main program containing the Window will perform a call to one of the algorithm’s functions from within the Matlab DLL file. This will run one iteration of the algorithm, by the end of which it will write the results to the local bmp file from above (“c:\a1.bmp”). Consequently the underlying data for the image has been updated and I would like for this to be reflected in the imgHolder component. For this purpose I am simply duplicating the code above whenever I return from the function.

The problem with this approach is that the algorithm will have around 100 iterations per run so this would have to happen 100 times. It just doesn’t seem right. I would be creating 100 different bitmap images all sourced from the same file.

Researching this I found out that one could use memorystream instead but I wonder whether this would be a drastical improvement or not as it seems that I would still have to create 100 images as the algorithm executes. Is it not possible to directly modify the underlying buffer somehow? I hear that GetPixel and SetPixel are not very efficient as they set a lock each time they are called. Is it possible perhaps to do this using the same _image object? If this was not a local file, I could’ve used a no cache option and it should’ve worked “by itself”. Having a no cache option with the file being local did not work because of the lock.

Does anyone have a better idea?

Thanks!

  • 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-29T10:48:24+00:00Added an answer on May 29, 2026 at 10:48 am

    I haven’t quite understood if you do have access to the bitmap’s raw data or not, or if it is always written to file. Since you mention SetPixel i guess you have.

    So you could perhaps use a WritableBitmap as _image.Source and cyclically update its content by one of its WritePixels methods.

    I just tried the following example which updates the image on every mouse move with a simple pattern.

    XAML:

    <Window ...>
       <Grid>
           <Image Name="image" />
       </Grid>
    </Window>
    

    Code:

    public partial class MainWindow : Window
    {
        private WriteableBitmap bitmap = new WriteableBitmap(100, 100, 96d, 96d, PixelFormats.Rgb24, null);
        private byte[] buffer = new byte[30000];
    
        public MainWindow()
        {
            InitializeComponent();
            image.Source = bitmap;
        }
    
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            Point pos = e.GetPosition(image);
            int offset = (int)pos.X + (int)pos.Y;
    
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = (byte)(i + offset);
            }
    
            bitmap.WritePixels(new Int32Rect(0, 0, 100, 100), buffer, 300, 0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this old Fortran executable that can only be accessed through its GUI,
I'm building a gui component that has a tree-based data model (e.g. folder structure
I am building an HTML Gui builder and this involves round-tripping HTML pages from
I need to create what I think should be a simple GUI. I have
I have always wondered about this but quite never got to understand why. We
I am building a small GUI interface and I have a QLabel that draws
I am working on building a GUI around a console application. I would like
I have a Monotouch iPad application for which I am trying to set up
Building a GUI system and I have a few classes for different GUI components
I am building a GUI for image processing in PyQt. One task that I

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.