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#
  4. Working with Bitmaps

Working with Bitmaps

Scheduled Pinned Locked Moved C#
helpgraphics
2 Posts 2 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.
  • B Offline
    B Offline
    BBatts
    wrote on last edited by
    #1

    Hello, I'm collecting bitmaps from a camera like below:

    private void LPRCamera2_OnNewFrame(object sender, ref Bitmap NewFrame)
    {
    while (LPR2List.Count >= LowCamSettings.LPR2FrameCount)
    {
    LPR2List[0].Dispose();
    LPR2List.RemoveAt(0);
    }

            if (lpr2FrameIndex >= LowCamSettings.LPR2SkipCount)
            {
                LPR2List.Add(new Bitmap(NewFrame));   //List object
                lpr2FrameIndex = 0;
            }
            else if (LowCamSettings.LPR2SkipCount > 0)
                lpr2FrameIndex++;
        }
    

    I then take the list (LPR2List) and pass it to a new object that copies the list to a local variable. Like so:

                for (int i = 0; i < LPR2List.Count; i++)
                {
                    if (LPR2List\[i\] != null)
                        this.Plate2List.Add((Bitmap)LPR2List\[i\].Clone());  //Error Line
                }
    

    Every now and then i'm getting an error when copying telling me that the object is in use. I haven't the slightest clue what I could be doing wrong. Any help would be greatly appreciated.

    T 1 Reply Last reply
    0
    • B BBatts

      Hello, I'm collecting bitmaps from a camera like below:

      private void LPRCamera2_OnNewFrame(object sender, ref Bitmap NewFrame)
      {
      while (LPR2List.Count >= LowCamSettings.LPR2FrameCount)
      {
      LPR2List[0].Dispose();
      LPR2List.RemoveAt(0);
      }

              if (lpr2FrameIndex >= LowCamSettings.LPR2SkipCount)
              {
                  LPR2List.Add(new Bitmap(NewFrame));   //List object
                  lpr2FrameIndex = 0;
              }
              else if (LowCamSettings.LPR2SkipCount > 0)
                  lpr2FrameIndex++;
          }
      

      I then take the list (LPR2List) and pass it to a new object that copies the list to a local variable. Like so:

                  for (int i = 0; i < LPR2List.Count; i++)
                  {
                      if (LPR2List\[i\] != null)
                          this.Plate2List.Add((Bitmap)LPR2List\[i\].Clone());  //Error Line
                  }
      

      Every now and then i'm getting an error when copying telling me that the object is in use. I haven't the slightest clue what I could be doing wrong. Any help would be greatly appreciated.

      T Offline
      T Offline
      TnTinMn
      wrote on last edited by
      #2

      I suspect that this is a threading issue. LPRCamera2_OnNewFrame appears to be an event handler and it may be raised on its own thread. See this SO answer[^] for a good explanation.

      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