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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Unable to read black and white image

Unable to read black and white image

Scheduled Pinned Locked Moved C#
helpgraphicsdata-structuresperformance
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.
  • C Offline
    C Offline
    code_explorer
    wrote on last edited by
    #1

    Dear Friends, I am using the following code to read colored (24 bit) image into array, but when I want to read black and white (1 bit image) it gives error "AccessViolationException unhandled" "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.": public static bool identifyLine(Bitmap imtooperated) { ArrayList blah = new ArrayList(); BitmapData bmData = new BitmapData(); Rectangle rect = new Rectangle(0, 0, imtooperated.Width, imtooperated.Height); bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly, imtooperated.PixelFormat); int stride = bmData.Stride; int range=0; unsafe { byte* p = (byte*)(void*)bmData.Scan0; for (int y = 0; y < imtooperated.Width; y++) { for (int x = 0; x < imtooperated.Height; x++) { blah.Add(p[range]); //here error comes range++; } p += 1; } p += stride; } imtooperated.UnlockBits(bmData); return true; } Please help.

    R 1 Reply Last reply
    0
    • C code_explorer

      Dear Friends, I am using the following code to read colored (24 bit) image into array, but when I want to read black and white (1 bit image) it gives error "AccessViolationException unhandled" "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.": public static bool identifyLine(Bitmap imtooperated) { ArrayList blah = new ArrayList(); BitmapData bmData = new BitmapData(); Rectangle rect = new Rectangle(0, 0, imtooperated.Width, imtooperated.Height); bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly, imtooperated.PixelFormat); int stride = bmData.Stride; int range=0; unsafe { byte* p = (byte*)(void*)bmData.Scan0; for (int y = 0; y < imtooperated.Width; y++) { for (int x = 0; x < imtooperated.Height; x++) { blah.Add(p[range]); //here error comes range++; } p += 1; } p += stride; } imtooperated.UnlockBits(bmData); return true; } Please help.

      R Offline
      R Offline
      rizgar
      wrote on last edited by
      #2

      dear code_explore replace this line bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly,imtooperated.PixelFormat); by bmData = imtooperated.LockBits(rect, ImageLockMode.ReadOnly,PixelFormat1bppIndexed,imtooperated.PixelFormat); you dont specify format for reading reqarding...

      eng. rizgar

      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