CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    14

    Image descriptors

    Hello, well I'm new at programming and C++, but for a program I am developing I need to use an image descriptor for a function that gets the RGB values from the image descriptor (the functions are from http://www.catenary.com) anyway I'm not sure I'm understanding everything about an image descriptor. I have read a few things about them and understand that they contain information about the image. It seems in the sample code I'm using though the image descriptor is never intialized. I need to have the image descriptor referring to an image on file (more specifically I need it to access the last photo saved by my program but that's not really relevant). So can anyone describe a way to do this or if this is even how image descriptors work?

  2. #2
    Join Date
    Jul 2010
    Posts
    14

    Re: Image descriptors

    Code:
    int loadjpgfilefrombuffer(LPTSTR fname, imgdes *image)
       {
       #define BAD_READ -87
       
       JpegData jdat;      // Reserve space for struct
       DWORD bytesRead, 
       int rcode = NO_ERROR;
       OFSTRUCT of_st;
       UCHAR huge *jpegbuff;
       HANDLE fhandle;
       DWORD filesize;
       
       // Load JPEG file into buffer
       fhandle = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, NULL);
       if(fhandle == INVALID_HANDLE_VALUE)
          return(BAD_OPN);
       // Get filesize
       filesize = GetFileSize(fhandle, NULL);
    
       CloseHandle(fhandle);  // Close the file
       
       // Allocate memory to hold file
       jpegbuff = (UCHAR huge *)GlobalAllocPtr(GMEM_MOVEABLE, filesize);
       if(jpegbuff == 0)
          return(BAD_MEM);   // Allocation failed!
          
       // Load JPEG file into memory
       fhandle = CreateFile(fname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ NORMAL, NULL);
       if(fhandle == INVALID_HANDLE_VALUE)
          return(BAD_OPN);
    
       ReadFile(fhandle, jpegbuff, filesize, &bytesRead, NULL);
       if(bytesRead == 0)
          rcode = BAD_READ;
       CloseHandle(fhandle);  // Close the file
       
       // Read the JPEG data from the buffer
       // Make sure JPEG data exists and get image dimensions
       rcode = jpeginfofrombuffer(jpegbuff, &jdat);
       if(rcode == NO_ERROR) {
          // Release the current image buffer
          freeimage(image);
          // Allocate the new image buffer to the file dimensions
          // This allocates a DIB to hold the image
          rcode = allocimage(image, jdat.width, jdat.length, jdat.vbitcount);
          if(rcode == NO_ERROR) {
             // Decompress the JPEG data
             rcode = loadjpgfrombuffer(jpegbuff, image);
             }   
          }
       GlobalFreePtr(jpegbuff); // Free allocated memory
       // Now the image is in the DIB and ready to process, display, or print
       return(rcode);
    }
    this is the sample code I was given that I am currently trying to get to work but it is saying image unitialized

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Image descriptors

    Quote Originally Posted by syg19 View Post
    this is the sample code I was given that I am currently trying to get to work but it is saying image unitialized
    Who (or what) a where is saying "image unitialized"?
    Besides, why are you closing the file and then opening it again with the same attributes?
    Victor Nijegorodov

  4. #4
    Join Date
    Jul 2010
    Posts
    14

    Re: Image descriptors

    Well the program compiles fine but when I try to take a picture (which is the action that initiates this code) I get an error message saying "Run-Time Check Failure #3 - The variable 'image' is being used without being initialized." As to your other question I don't really know I'm trying to use image processing tools provided by catenary.com this is a "sample" code they provide which I'm trying to get to work before.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured