图像任意比缩放
已经读取数据为unsigned char类型,8位灰度图像如何进行任意比例的缩放。求思路,或者代码。
[解决办法]
- C/C++ code
void copy_row2_B (BYTE *src, int src_w, BYTE *dst, int dst_w) { int i; int pos, inc; BYTE pixel = 0; pos = 0x10000; inc = (src_w << 16) / dst_w; for ( i=dst_w; i>0; --i ) { while ( pos >= 0x10000L ) { pixel = *src++; pos -= 0x10000L; } *dst++ = pixel; pos += inc; } }// src 源缓冲, dst 目的缓冲, sw 源图片宽, dw 目的图片宽, rsrc 源区域, rdes 目的区域 void StretchBlt_B(BYTE* src, BYTE* dst, int sw, int dw, RECT* rsrc, RECT* rdes) { int pos, inc; int dst_width; int dst_maxrow; int src_row, dst_row; BYTE *srcp = NULL; BYTE *dstp; /* Set up the data... */ pos = 0x10000; inc = (rsrc->h() << 16) / rdes->h(); src_row = rsrc->top; dst_row = rdes->top; dst_width = rdes->w(); /* Perform the stretch blit */ for ( dst_maxrow = dst_row+rdes->h(); dst_row<dst_maxrow; ++dst_row ) { dstp = (BYTE *)dst + (dst_row*dw) + (rdes->left); while ( pos >= 0x10000L ) { srcp = (BYTE *)src + (src_row*sw) + (rsrc->left); ++src_row; pos -= 0x10000L; } copy_row2_B(srcp, rsrc->w(), dstp, rdes->w()); pos += inc; } }