raver

raver

  • NA
  • 6
  • 0

Need Help Converting C to C#

Jun 15 2006 2:27 PM

I have some code that I'm told that I HAVE to convert from C to C#.  I'm not sure what some members would be converted to in C#.  The chunk of code where I'm really lost is below.  For example what would fseek() be converted to in C#?  Is there a good website or book that would help me convert from C to C#?  Anyway, here's the code that I REALLY need help on:

{
            int i;
            unsigned long Offset;      
            long Width, Height, LineDelta;     

            /* Get size and offset to video data */
            fseek(ImageFile, 10, SEEK_SET);
            fread_endian(&Offset, sizeof(Offset), 1, ImageFile);
            fseek(ImageFile, 18, SEEK_SET);
            fread_endian(&Width, sizeof(Width), 1, ImageFile);
            fread_endian(&Height, sizeof(Height), 1, ImageFile);
            if (Verbose >= 3)
               fprintf(OutFile, "Size = %d x %d\n   Offset = %d\n",
                  (int) Width, (int) Height, (int) Offset);
            LineDelta = (Width + 3) & (~3);

            /* Allocate heap space for image */
            if (NULL != ImageData)  /* free last allocation, if any */
               free(ImageData);

            ImageData = (unsigned char *) malloc(LineDelta * Height);
            if (ImageData == NULL)
            {
               fprintf(OutFile, "Can't allocate %d bytes for image data\n",
                  (int) (LineDelta * Height));
               goto Exit;
            }

            /* Read in the video data, accounting for bottom up organization of .BMP files */
            for (i = 0; i < Height; i++)
            {
               fseek(ImageFile, Offset + (Height - i - 1) * LineDelta, SEEK_SET);
               fread(ImageData + i * LineDelta, LineDelta, 1, ImageFile);
               #ifdef IMAGE_FILE_PROGRESS
                  printf("Line = %d\n", i);
               #endif
            }
            fclose(ImageFile);
            ImageFile = NULL;

            break;
         }


If any other code from the file is needed, please let me know.  Thanks!