Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with CBitmap (MFC prog)

Problem with CBitmap (MFC prog)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicstutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LordOfSword
    wrote on last edited by
    #1

    I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do

    J P J 3 Replies Last reply
    0
    • L LordOfSword

      I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do

      J Offline
      J Offline
      JWood
      wrote on last edited by
      #2

      I don't know the exact deatils but you might want to try pDC->SelectObject(&bm); It may need a device context to do what you want it to do. Threads share memory space within a process, so I don't see how that would affect it.

      1 Reply Last reply
      0
      • L LordOfSword

        I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do

        P Offline
        P Offline
        PengFeidu
        wrote on last edited by
        #3

        hi! When you saved the temp file , I think you didnot make the properly bitmap header which is a struct "BITMAPINFO". so it displayed blank picture. good luck dupengfei

        1 Reply Last reply
        0
        • L LordOfSword

          I have a problem with CBitmaps. I want to copy one bitmap into another, which wouldn’t be a problem if I didn’t use multithreading. My situation is this: I made a program which calculates the Mandelbrot fractal. I have a bitmap in which the picture is saved and which is used to make it display in the window. The function calculating the fractal creates a temporary bitmap and after it has finished, I want to copy the temporary image to the main image which is used to display but I receive either an assertion error or the bitmap becomes blank (white). The problem only occurs when I run the function in a separate thread but if I don’t use multithreading, all works fine… I tried a lot of things (for example using the BitBlt-function or working with pointers to the bitmaps) but none really helps. The weird thing is, that even if I get the assertion error, the program displays the bitmap correctly (only on some comps!). I gave it to a friend to test it (he has the same OS as me, Win2000 Professional) but it didn’t show the image (only a white window). It also seems to work correctly under WinXP. I’m running out of ideas, so please give me some suggestions what to do

          J Offline
          J Offline
          Jagadeesh VN
          wrote on last edited by
          #4

          I presume, you are having problems with multi-threading. 'A thread is supposed to access only those objects which it has created'. If you are trying to copy the new bitmap from the processing thread( not the main thread ) to the Bitmap object created by your main thread, then you have a problem. A workaround would be, to use user-defined windows messages after you are finished with your processing, and thereby notifying your main thread, to copy the newly created bitmap to the original one. Hope this helps!!! "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

          L 1 Reply Last reply
          0
          • J Jagadeesh VN

            I presume, you are having problems with multi-threading. 'A thread is supposed to access only those objects which it has created'. If you are trying to copy the new bitmap from the processing thread( not the main thread ) to the Bitmap object created by your main thread, then you have a problem. A workaround would be, to use user-defined windows messages after you are finished with your processing, and thereby notifying your main thread, to copy the newly created bitmap to the original one. Hope this helps!!! "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

            L Offline
            L Offline
            LordOfSword
            wrote on last edited by
            #5

            I thought of what you mentioned but I found another way to get the program nearly working as I want. I use the PeekMessage-function in the calculation function. This works properly but if you click in the menu, the calculation will stop until you leave it. But I'm statisfied how it works now. And of course thanks to all who posted suggestions :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups