Bitmap Rohdaten blitten?



  • Hi,

    Wie kann man Image-Rohdaten aus einer bmp Datei an ein HDC übergeben oder schlicht auf den Bildschirm zeichnen?

    // Load bitmap file
    long __stdcall LoadBitmapFile(HDC hdc, char *filename, char *data)
    {
    	FILE				*filePtr;			// file pointer
    	BITMAPFILEHEADER	bitmapFileHeader;	// bitmap file header	
    	BITMAPINFOHEADER	bitmapInfoHeader;	// bitmap info header
    	unsigned char		*bitmapImage;		// bitmap image data
    
    	unsigned long		imageIdx = 0;		// image index counter
    	unsigned char		tempRGB;			// swap variable
    
    	// open filename in "read binary" mode
    	filePtr = fopen(filename, "rb");
    
    	if(filePtr == NULL)
    	{
    		MessageBox(NULL, "No file", "Error", MB_OK);
    		return 0;
    	}
    
    	// read the bitmap file header
    	fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
    
    	// verify that this is a bitmap by checking for the univeral bitmap id
    	if(bitmapFileHeader.bfType != BITMAP_ID)
    	{
    		fclose(filePtr);
    		MessageBox(NULL, "No bitmap file", "Error", MB_OK);
    		return 0;
    	}
    
    	// read the bitmap information header
    	fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
    
    	// move file pointer to beginning of bitmap data
    	fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
    
    	// allocate enough memory for the bitmap image data
    	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader.biSizeImage);
    
    	// verify memory allocation
    	if(!bitmapImage)
    	{
    		free(bitmapImage);
    		fclose(filePtr);
    		MessageBox(NULL, "Memory allocation error", "Error", MB_OK);
    		return 0;
    	}
    
    	// read in the bitmap image data
    	fread(bitmapImage, 1, bitmapInfoHeader.biSizeImage, filePtr);
    
    	// make sure bitmap data was read
    	if(bitmapImage == NULL)
    	{
    		fclose(filePtr);
    		MessageBox(NULL, "Couldn't read bitmap data", "Error", MB_OK);
    		return 0;
    	}
    
    	// swap the R and B values to get RGB since the bitmap color format is in BGR
    	for(imageIdx = 0; imageIdx < bitmapInfoHeader.biSizeImage; imageIdx+=3)
    	{
    		tempRGB = bitmapImage[imageIdx];
    		bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
    		bitmapImage[imageIdx + 2] = tempRGB;
    	}
    
    	// copy image data into the data parameter
    	memcpy(data, bitmapImage, len);
    
    	// blit image to hdc
    	BitBlt(hdc, 0, 0, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, SOURCE_HDC, 0, 0, SRCCOPY);
    // -> Wie bekommt man die Image-Rohdaten "data" in ein HDC um es per BitBlt auf einen anderen HDC anzeigen zu können?
    
    	// free memory
    	free(bitmapImage);
    
    	// close the file and return the bitmap image data
    	fclose(filePtr);
    
    	return 1;
    }
    


  • Du willst SetDIBits oder SetDIBitsToDevice.


Anmelden zum Antworten