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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:22:11+00:00 2026-05-16T16:22:11+00:00

I am using the function below to capture an image on a different form.

  • 0

I am using the function below to capture an image on a different form. The captured image is then fed to an OCR app, in this instance tesseract. The issue that I am having is that when the image is copied to the bitmap the quality drops to 96dpi and I want to keep it either at 1 to 1 or at least 300 dpi and also scale it *2 as the text on the image is a little small. I did not write the capture function and am wondering if anyone has any recommendations as to how I can modify it to up the quality of the returned Bitmap.

I have since learnt that the default dpi of image captures is actually 96dpi, you can enlarge any text to 120dpi but that didn’t really help in this instance. The only option is to capture the image and then resize it. So far I have found a couple of ways of doing this, one below which I modified to use stretchBlt and another which I create another larger bitmap and then bitblt it onto this new enlarged bitmap which has a higher dpi with this like bicubic scaling set to high. So far I am able to get a correct OCR rate of about 75 – 90% which isn’t bad, but I didn’t get the cookie.

public static Bitmap Capture(IntPtr hwnd, int x, int y, int width, int height)
        {
            //Size contains the size of the screen
            SIZE size;

            //hBitmap contains the handle to the bitmap
            IntPtr hBitmap;

            //Get handle to the desktop device context
            IntPtr hDC = PlatformInvokeUSER32.GetDC(hwnd);

            //Device context in memory for screen device context
            IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);

            //Pass SM_CXSCREEN to GetSystemMetrics to get the X coordinates 
            //of the screen
            size.cx = width;

            //As above but get Y corrdinates of the screen
            size.cy = height;

            //Create a compatiable bitmap of the screen size using the 
            //screen device context
            hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, size.cx, size.cy);

            //Cannot check of IntPtr is null so check against zero instead
            if (hBitmap != IntPtr.Zero)
            {
                //Select the compatiable bitmap in the memeory and keep a 
                //refrence to the old bitmap
                IntPtr hOld = (IntPtr)PlatformInvokeGDI32.SelectObject(hMemDC, hBitmap);

                //Copy bitmap into the memory device context
                bool b = PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, x, y, PlatformInvokeGDI32.SRCOPY);

                //Select the old bitmap back to the memory device context
                PlatformInvokeGDI32.SelectObject(hMemDC, hOld);

                //Delete memory device context
                PlatformInvokeGDI32.DeleteDC(hMemDC);

                //Release the screen device context
                PlatformInvokeUSER32.ReleaseDC(hwnd, hDC);

                //Create image
                Bitmap bmp = System.Drawing.Image.FromHbitmap(hBitmap);

                //Release memory to avoid leaks
                PlatformInvokeGDI32.DeleteObject(hBitmap);

                //Run garbage collector manually
                GC.Collect();

                //Return the bitmap
                return bmp;

            }

            else
            {

                return null;

            }

        }

        #endregion

    }

Thanks R.

  • 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-16T16:22:12+00:00Added an answer on May 16, 2026 at 4:22 pm

    Instead of using BitBlt, you can use StretchBlt.

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

Sidebar

Related Questions

Using the SQL in the below code: public function saveOrder() { $id = $this->getUserId();
Basically, the code below will generate divs which are then captured using the jquery
I am using the function below inside a thread to receive the byte[] via
I am using the function below to open the user's default web browser. Public
First of all, i'm using the function below to read data from a pdf
Anyone experienced exception using below function? tdse.GetObject(tmpFolderWebDavURL, EnumOpenMode.OpenModeView, null, XMLReadFilter.XMLReadAll) as Folder; Seems if
i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
I have a problem using the string function erase with iterators. The function below
I am using the below function of javascript to enable and disable the radio
I am using Serial port to receive the messages. The below function is running

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.