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 6703979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:14:08+00:00 2026-05-26T07:14:08+00:00

I have my own classes that represent image data. They have various underlying structure

  • 0

I have my own classes that represent image data. They have various underlying structure but all have indexed property which returns an i,j-th image element. I need to display such images in a form. Right now I pre-convert them to System.Drawing.Bitmap and then display it in a standard Winforms PictureBox. My idea is to create a custom control that will have a property of my image type and will display a picture without preliminary converting it to System.Drawing.Bitmap or System.Drawing.Image.

I suggest that the clue to this problem is creating a user-drawn control and overriding OnPaint event there.

protected override void  OnPaint(PaintEventArgs e)
    {
        for(int i=e.ClipRectangle.Left; i<=e.ClipRectangle.Right; i++)
        {
            for (int j = e.ClipRectangle.Top; j <= e.ClipRectangle.Bottom; j++)
            {
                //do something with i and j here
                //calculate the corresponding k and l indices
                //assign _myCustomClassImage[k,l] somewhere
            }
        }

    }

Yes, I understand that I can create Bitmap of the clip rectangle’s size and use SetPixel to assign it’s elements but SetPixel works very slowly.

Another idea is to use marshalling to assign bitmap’s pixels but the whole idea of creating a bitmap inside an OnPaint event handler seems quite lame.

Are there any suggestions in what direction should I continue my work?

  • 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-26T07:14:08+00:00Added an answer on May 26, 2026 at 7:14 am

    Creating a custom control and overriding the OnPaint method would be of value if the data you wanted to display were vectorial in some way. If you have an image to display, there does not seem to be a better alternative than creating a Bitmap object.

    I know SetPixel is slow and I am not sure what you mean with ‘use marshalling to assign bitmap’s pixels’ but there is a fast alternative using the System.Drawing.Imaging.BitmapData class and Bitmap.LockBits method. See an example usage here.

    By the way, why do you need to create the Bitmap object in the OnPaint method? Is not creating and assigning it once enough?

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

Sidebar

Related Questions

I have a wxPython application with the various GUI classes in their own modules
I have my own game engine using C++ and OpenGL, but I have models
I have my own custom Content Provider that loads a database which contains the
Working with the MVVM pattern, I have a pair of view model classes that
We're using interfaces to represent entity classes in our domain model. We have concrete
In a new piece of code I have several different classes that refer to
I have a number of LINQ classes that inherit from the same base class.
I have one interface that contains four functions. I have about 20 classes that
I'm Programing in C++, and I have 3 classes that inherit from each other:
I have a base-class called Element. Some other classes (like Label and Image) both

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.