Archived

This topic is now archived and is closed to further replies.

Resizing bitmap.

This topic is 5150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. 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); 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); -------------------------------------------------------------------------------- The above code is not compilable but should give a rough idea of what I am doing. When I attempt to add resizing in the picture I get an empty black image: 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); -------------------------------------------------------------------------------- Is my use of StretchDIBits and GetDIbits correct? I have tried GetLastError and all I get is ERR_SUCCESS. Am I missing something else? Any help would be greatly appreciated. Cheers.

Share this post


Link to post
Share on other sites