Hi. I'm trying to write function to resizing images. Below is function which do that but only in x axis and scale = 50%, 25%, 12,5% etc. I need function resizing image in x and y axis with any scale. How to do that ? Thank for any help...
RGBA is my own structure
pBits - pointer to (oryginal) image's bits
pBitsNew - pointer to (resized) image's bits
Code:BOOL epfBitmap::SetSize (int xSize, int ySize) { BYTE * pBitsNew ; // Calculate bytes to allocate int iByteCount = ySize * (((xSize * iBitsPixel + 15) & ~15) >> 3) ; // Alocate momory for bits of new bitmap pBitsNew = (BYTE *) malloc (iByteCount) ; if (pBitsNew == NULL) { MessageBox (NULL, TEXT("Can't allocate memory!"), NULL, MB_OK | MB_ICONERROR) ; return FALSE ; } // Create RGBA pointers RGBA * pRGBANew = (RGBA *) pBitsNew ; RGBA * pRGBA = (RGBA *) pBits ; // Resizing bitmap float fxScale = (float) cx / xSize ; float fyScale = (float) cy / ySize ; float fxScale2 = fxScale ; float fyScale2 = fyScale ; int iSumRed = 0 ; int iSumGreen = 0 ; int iSumBlue = 0 ; int iSumAlpha = 0 ; for (int y = 0; y < cy; y++) { for (int x = 0; x < cx; x++, pRGBA++) { if(fxScale2 <= 0) { fxScale2 = fxScale ; pRGBANew->rgbRed = (int) ((float)iSumRed / fxScale) ; pRGBANew->rgbGreen = (int) ((float)iSumGreen / fxScale) ; pRGBANew->rgbBlue = (int) ((float)iSumBlue / fxScale) ; pRGBANew->rgbAlpha = (int) ((float)iSumAlpha / fxScale) ; iSumRed = 0 ; iSumGreen = 0 ; iSumBlue = 0 ; iSumAlpha = 0 ; pRGBANew++ ; } fxScale2-- ; iSumRed += pRGBA->rgbRed ; iSumGreen += pRGBA->rgbGreen ; iSumBlue += pRGBA->rgbBlue ; iSumAlpha += pRGBA->rgbAlpha ; } } cx = xSize ; cy = ySize ; pBits = (BYTE *) realloc (pBits, iByteCount) ; pBits = pBitsNew ; return TRUE ; }



LinkBack URL
About LinkBacks


