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. How to display image in View?

How to display image in View?

Scheduled Pinned Locked Moved C / C++ / MFC
cssdata-structurestutorialquestion
3 Posts 3 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.
  • J Offline
    J Offline
    Jerry Wang 0
    wrote on last edited by
    #1

    Hello, I'm new to dealing with graphical user interfaces and currently I am working on a program that would need to display an acquired image onto the screen. The image is an array of unsigned char buffer containing the RGB values. Would anyone know how I may display it effeciently in my view? Currently, I am doing a nested for loop inside OnDraw() and I don't believe this is the correct way. Don't laugh :-O , but here's what I've got-- BYTE R, G, B; for (unsigned long y=0; y "less than" imageHeight; y++) { for (unsigned long x=0; x "less than" imageWidth; x++) { R = imageBuffer[(y*imageWidth*3)+(x*3)]; G = imageBuffer[(y*imageWidth*3)+(x*3)+1]; B = imageBuffer[(y*imageWidth*3)+(x*3)+2]; cDC->SetPixel(x, y, RGB(R,G,B)); } } Thanks in advance! Jerry

    C N 2 Replies Last reply
    0
    • J Jerry Wang 0

      Hello, I'm new to dealing with graphical user interfaces and currently I am working on a program that would need to display an acquired image onto the screen. The image is an array of unsigned char buffer containing the RGB values. Would anyone know how I may display it effeciently in my view? Currently, I am doing a nested for loop inside OnDraw() and I don't believe this is the correct way. Don't laugh :-O , but here's what I've got-- BYTE R, G, B; for (unsigned long y=0; y "less than" imageHeight; y++) { for (unsigned long x=0; x "less than" imageWidth; x++) { R = imageBuffer[(y*imageWidth*3)+(x*3)]; G = imageBuffer[(y*imageWidth*3)+(x*3)+1]; B = imageBuffer[(y*imageWidth*3)+(x*3)+2]; cDC->SetPixel(x, y, RGB(R,G,B)); } } Thanks in advance! Jerry

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      the quickest way to do this is to create a DIB from your RGB buffer. a DIB is a rather complex data structure that holds a Device Independent Bitmap. but, to make a 24-bit DIB out of an RGB buffer you need to do the following: 1. allocate enough memory for the DIB. this is a BITMAPINFOHEADER plus the pixels. pixels in a 24-bit DIB are 3 bytes per pixel with 1-3 bytes at the end of each row so that the number of bytes in a row is multiple of 4. 2. fill in the member of the BITMAPINFOHEADER struct 3. copy the RGB pixels into the DIB so that the DIB is vertically flipped compared to the RGB buffer and R and B are swapped. 4. call StretchDIBits. if you want a working sample of all this, see JpegFile. this is a JPG read/write class that deals with RGB images (from/to JPG) and DIBs (for display). -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

      1 Reply Last reply
      0
      • J Jerry Wang 0

        Hello, I'm new to dealing with graphical user interfaces and currently I am working on a program that would need to display an acquired image onto the screen. The image is an array of unsigned char buffer containing the RGB values. Would anyone know how I may display it effeciently in my view? Currently, I am doing a nested for loop inside OnDraw() and I don't believe this is the correct way. Don't laugh :-O , but here's what I've got-- BYTE R, G, B; for (unsigned long y=0; y "less than" imageHeight; y++) { for (unsigned long x=0; x "less than" imageWidth; x++) { R = imageBuffer[(y*imageWidth*3)+(x*3)]; G = imageBuffer[(y*imageWidth*3)+(x*3)+1]; B = imageBuffer[(y*imageWidth*3)+(x*3)+2]; cDC->SetPixel(x, y, RGB(R,G,B)); } } Thanks in advance! Jerry

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Maybe when the image is first aquired you could create a CBitmap and us the SetBitmapBits method. Then in your OnDraw you could render the bitmap instead of processing the the array each time. Just a possiblity, don't know if it will work for you. Also, for future you can use the <pre> or <code> tags for any code snippets. Or at least use the HTML encoding < rather than "less than"

        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