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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:30:46+00:00 2026-05-31T20:30:46+00:00

I need to render a 1027 * 768 bitmap to the client window (same

  • 0

I need to render a 1027 * 768 bitmap to the client window (same size) and I don’t have more than 10-15 ms to complete this task. I am using bufferedGraphics allocated from a bufferedGraphicsContect object and still notice huge performance issues.

I am using unsafe code to perform my copy operations and found unbelievable results. I know the Graphics / BufferedGraphics objects should have some sort of a drawing surface in memory. I was wondering if someone could point me in the right direction on how to write to this surface using Marshal or some other unsafe low level method.

I am in the process of porting an older c# graphics application. I know c# is not designed for heavy graphics and that there are better tools than GDI+ available, unfortunately I don’t have those luxuries.

This is what I have come up with so far… Any insight what so ever is greatly apperciated.

byte[] _argbs = null;
static readonly Bitmap _bmUnderlay = Properties.Resources.bg;
static Bitmap _bmpRender = new Bitmap(1024, 768, System.Drawing.Imaging.PixelFormat.Format24bppRgb); 
int bmpHeight = Properties.Resources.bg.Height;
int bmpWidth = Properties.Resources.bg.Width;
static BufferedGraphicsContext _bgc = new BufferedGraphicsContext();

internal unsafe void FillBackBuffer(Point cameraPos)
{
        // lock up the parts of the original image to read (parts of it)
        System.Drawing.Imaging.BitmapData bmd = _bmUnderlay.LockBits(
            new Rectangle(cameraPos.X, cameraPos.Y, 1024, 768),
            System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        // get the address of the first line.
        IntPtr ptr = bmd.Scan0;

        //if (_argbs == null || _argbs.Length != bmd.Stride * bmd.Height)
        //    _argbs = new byte[bmd.Stride * bmd.Height];
        if (_argbs == null || _argbs.Length != 1024 * 3 * 768)
            _argbs = new byte[1024 * 3 * 768];

        // copy data out to a buffer
        Marshal.Copy(ptr, _argbs, 0, 1024 * 3 * 768);

        _bmUnderlay.UnlockBits(bmd);

        // lock the new image to write to (all of it)
        System.Drawing.Imaging.BitmapData bmdNew = _bmpRender.LockBits(
            new Rectangle(0, 0, 1024, 768),
            System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        // copy data to new bitmap
        Marshal.Copy(_argbs, 0, bmdNew.Scan0, 1024 * 3 * 768);
        _bmpRender.UnlockBits(bmdNew);
}

private unsafe void _btnGo_Click(object sender, EventArgs e)
{
    // less than 2 ms to complete!!!!!!!!
    FillBackBuffer(new Point());

    using (BufferedGraphics bg = _bgc.Allocate(CreateGraphics(), ClientRectangle))
    {
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        /////
        ///
        // This method takes over 17 ms to complete
        bg.Graphics.DrawImageUnscaled(_bmpRender, new Point());
        //
        ///
        /////
        sw.Start();
        this.Text = sw.Elapsed.TotalMilliseconds.ToString();

        bg.Render();
    }
}

EDIT:

Forgot to mention I’m looking for a low level alternative to Graphics.DrawImage(), preferrably writing to Graphics surface memory, using pointers? Thanks again

  • 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-31T20:30:47+00:00Added an answer on May 31, 2026 at 8:30 pm

    Pay attention to the pixel format of the bitmap. On standard 32bpp video hardware, Format32bppPArgb renders ten times faster than any of the other ones. Because the pixels don’t need any translation. The 24bpp format you use now needs to be widened to 32bpp and that doesn’t come for free. Don’t skip the P of PArgb and don’t forget to set the alpha value to 255 in your code.

    Using BufferedGraphics is fishy btw. You should always use the one you get for free in the OnPaint method. And you probably don’t need one at all since you’re blitting this fast. That’s an automatic 2x speed-up.

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

Sidebar

Related Questions

On the iPad, I need to render a large pdf (more than 1gb). For
I have a workflow where I need to render an exception page. But this
I have a report which is composed of several subreports. I need to render
EDIT: All I need is render /devise/registrations/edit in /settings/password To do that put this
Im need render this remplate with Rails.root <%= escape_javascript(render(:template => '#{Rails.root}/app/controllers/posts/repost_new'))%> but I get
I have a table that I need to render some vertical text in one
In my model I have: after_create :push_create I push_create I need to render a
I need to render a DropDown list and I don't want to pass list's
I have the need to render some html text (not an html page with
I have some ODF files with math formulas and I need to render them...or

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.