Greetings,
I am trying to resize a bitmap in memory using
StretchDIBits and GetDIBits and, in turn, output
the file to a BIP format.
Without resizing the following code works fine
when outputting a BIP.
The above code is not compilable but shouldCode:out_byte = (BYTE *) calloc(NCOLS*JP2_CHANNELS,1); if (out_byte == NULL) return false; out_data = (BYTE *) calloc(NCOLS*NROWS*JP2_CHANNELS,1); if (out_data == NULL) { free(out_byte); return false; } // Open output bip and hdr files. success = true; success = success && (! ((out_bip = fopen(bip_path,"wb")) == NULL)); success = success && (! ((out_hdr = fopen(hdr_path,"w")) == NULL)); // Get source image // Contains Data and BITMAPINFO header. GetImage(Path,this->m_timage); BYTE *pData = (BYTE *)this->m_timage.Data; // Have to flip bmp and change windows BGR to RGB. for(int y = NROWS - 1; y >= 0; y--) { pData2 += (y * NCOLS * JP2_CHANNELS); for(int x = 0; x < NCOLS*JP2_CHANNELS; x+=JP2_CHANNELS) { out_byte[x] = pData2[2]; //R out_byte[x+1] = pData2[1]; //G out_byte[x+2] = pData2[0]; //B pData2 += 3; } // Write out entire line. fwrite(out_byte,1,NCOLS*JP2_CHANNELS,out_bip); // Reset pData to bottom of image. //pData = (BYTE *)this->m_timage.Data; pData2 = out_data; } free (out_byte); free (out_data);
give a rough idea of what I am doing.
When I attempt to add resizing in the picture
I get an empty black image:
Is my use of StretchDIBits and GetDIbits correct?Code:out_byte = (BYTE *) calloc(NCOLS*JP2_CHANNELS,1); if (out_byte == NULL) return false; out_data = (BYTE *) calloc(NCOLS*NROWS*JP2_CHANNELS,1); if (out_data == NULL) { free(out_byte); return false; } // Open output bip and hdr files. success = true; success = success && (! ((out_bip = fopen(bip_path,"wb")) == NULL)); success = success && (! ((out_hdr = fopen(hdr_path,"w")) == NULL)); // Get source image // Contains Data and BITMAPINFO header. GetImage(Path,this->m_timage); HDC MemDC = CreateCompatibleDC(NULL); //HBITMAP BmpHnd = CreateBitmap(NCOLS,NROWS,1,24,NULL); HBITMAP BmpHnd = CreateCompatibleBitmap(MemDC, NCOLS, NROWS); HBITMAP OldBmp = (HBITMAP) SelectObject(MemDC,BmpHnd); StretchDIBits(MemDC,0,0,NCOLS,NROWS,0,0,this->Cols,this->Rows,this->m_timage.Data,&(this->m_timage.Info),DIB_RGB_COLORS,SRCCOPY); int numScanned = GetDIBits(MemDC,BmpHnd,0,NROWS-1,out_data,&Info,DIB_RGB_COLORS); char t[256]; sprintf(t, "num scanned: %d\n", numScanned); OutputDebugString(t); //int err = GetLastError(); //char t[256]; //sprintf(t, "error message: %d\n", err); //OutputDebugString(t); SelectObject(MemDC,OldBmp); DeleteObject(BmpHnd); BYTE *pData = out_data; // Have to flip bmp and change windows BGR to RGB. for(int y = NROWS - 1; y >= 0; y--) { pData2 += (y * NCOLS * JP2_CHANNELS); for(int x = 0; x < NCOLS*JP2_CHANNELS; x+=JP2_CHANNELS) { out_byte[x] = pData2[2]; //R out_byte[x+1] = pData2[1]; //G out_byte[x+2] = pData2[0]; //B pData2 += 3; } // Write out entire line. fwrite(out_byte,1,NCOLS*JP2_CHANNELS,out_bip); // Reset pData to bottom of image. //pData = (BYTE *)this->m_timage.Data; pData2 = out_data; } free (out_byte); free (out_data);
Am I missing something else?
Any help would be greatly appreciated.
Cheers.



LinkBack URL
About LinkBacks


