单色图的缩小
来源:互联网 发布:富士康java工程师待遇 编辑:程序博客网 时间:2024/04/28 18:32
///////////////////////////////////////////////////////////////////
// Function name : ZoomOutBmp
// Description : creates a new bitmap which is a grayscale
// zoomed out version of the original
// Return type : HDIB - handle to a new bitmap
// Argument : double zoom - number of times to zoom out
// Argument : HDIB hSrcDIB - handle to a source bitmap
///////////////////////////////////////////////////////////////////
HDIB JpegFile::ZoomOutBmp(double zoom, HDIB hSrcDIB)
{
if (hSrcDIB == NULL) // nothing to do
return NULL;
if (zoom < 1) // no zoomin in this function
return NULL;
LPSTR pSrcDIB = (LPSTR) ::GlobalLock((HGLOBAL) hSrcDIB);
BITMAPINFOHEADER& bmihSrc = *(BITMAPINFOHEADER*)pSrcDIB;
//ASSERT(bmihSrc.biBitCount == 1); // only monochrome bitmaps supported
LPSTR pSrcBits = (LPSTR) (pSrcDIB + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*2);
BITMAPINFOHEADER bmihDst = bmihSrc;
bmihDst.biWidth = (LONG)(bmihDst.biWidth / zoom + 0.5);
bmihDst.biHeight = (LONG)(bmihDst.biHeight / zoom + 0.5);
bmihDst.biBitCount = 8; // grayscale in any case
bmihDst.biClrUsed = 0;
// prepare destination bitmap
DWORD dwDIBSize = sizeof(bmihDst) + sizeof(RGBQUAD)*256 +
WIDTHBYTES(bmihDst.biWidth * bmihDst.biBitCount) * bmihDst.biHeight;
bmihDst.biSizeImage = dwDIBSize;
// allocate space for the new bitmap
HDIB hDstDIB = (HDIB) ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, dwDIBSize);
if (hDstDIB == 0) {
::GlobalUnlock((HGLOBAL) hSrcDIB);
return NULL;
}
LPSTR pDstDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDstDIB);
// copy header
memcpy(pDstDIB, &bmihDst, sizeof(bmihDst));
// prepare grayscale palette
for (int i=0; i < (1 << bmihDst.biBitCount); i++) {
RGBQUAD& palEntry = *(RGBQUAD*)(pDstDIB + sizeof(bmihDst) + i * sizeof(RGBQUAD));
palEntry.rgbRed = palEntry.rgbGreen = palEntry.rgbBlue = i;
}
LPSTR pDstBits = (LPSTR) (pDstDIB + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
// now fill the bits
LPSTR curSrcLineBits, curDstLineBits;
int j, k;
int scale = (int)(zoom + 0.5); // integer zoom out factor, i.e. 1:5
int hBase, vBase;
unsigned char value;
// for every _scale_ lines in a source bitmap we will get one line
// in the destination bitmap. Similarly for _scale_ columns in the
// source we'll obtain one destination column.
for (int strip=0; strip < bmihDst.biHeight; strip++) { // for every dst line
curDstLineBits = pDstBits + strip * WIDTHBYTES(bmihDst.biWidth * bmihDst.biBitCount);
vBase = int(strip * zoom + 0.5);
for (int i=0; i < scale; i++) { // accumulate _scale_ rows
curSrcLineBits = pSrcBits + (vBase + i) * WIDTHBYTES(bmihSrc.biWidth * bmihSrc.biBitCount);
// prepare horizontally condensed lines for this strip
for (j=0; j < bmihDst.biWidth; j++) { // for all bits in line
hBase = int(j * zoom + 0.5); // mapped index on source
for (k=0; k < scale; k++) { // accumulate _scale_ columns
value = (curSrcLineBits[(hBase+k)/8] & (1 << (7 - (hBase+k)%8))) ? 0xff : 0;
curDstLineBits[j] += value / scale / scale; // main accumulator
}
}
}
}
// unlock memory
::GlobalUnlock((HGLOBAL) hSrcDIB);
::GlobalUnlock((HGLOBAL) hDstDIB);
return hDstDIB;
}
- 单色图的缩小
- 单色位图的读取
- 单色位图的联通性
- 11.VC(ui)-单色图与彩色图之间的转换
- 完全自适应的单色或单线圆角框
- 如何获取RGB图像的单色图像
- 获取单色位图指定坐标的数据
- 获取最长单色子路径的长度
- PHP中大图缩小图的实例
- 基于S3C44B0X的128x64单色LCD编程控制
- Android中将bitmap转换成单色的BMP图片
- CAGradientLayer颜色的渐变(单色、多色、动画)
- [真正的单色三角形] BZOJ 3498 PA2009 Cakes
- Unity 绿幕抠图 摄像头抠图 单色抠图
- Unity 绿幕抠图 摄像头抠图 单色抠图
- 将任何普通图片转换为单色图
- 单色三角形
- 放大缩小的代码
- 最简短最容易理解的js的Array操作
- 常用的CSS命名规则
- Event
- 完整24位真彩色位图灰度化源代码
- 迷客口语:SEO项目流程操作及中小网站优化技巧
- 单色图的缩小
- 事件驱动的工作流过程链模型EPC
- Shell 编程速成(1)
- linux shell编程
- 将C/C++头文件转换成C#的解释器
- AIR中文帮助 第一章 什么是 Adobe AIR
- 电脑总是无故自动关机、自动重启和死机原因
- Mime type with javascript----text/javascript,application/javascript, and appliation/x-javascript
- 写Makefile(二)