ObjectARX 构建鼠标跟随图像之acedAddSupplementalCursorImage简单实例

发布时间 2023-04-12 23:44:18作者: edata

ObjectARX 2015 新增了一个api acedAddSupplementalCursorImage

代码

		CBitmap   cbmp;
		cbmp.m_hObject=(HBITMAP)::LoadImage(NULL,_T("d:\\test.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
		BITMAP bm;
		cbmp.GetBitmap(&bm);
		int nByte=bm.bmBitsPixel /8;
		BITMAPINFO bi;
		bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
		bi.bmiHeader.biWidth=bm.bmWidth;
		bi.bmiHeader.biHeight=-bm.bmHeight;
		bi.bmiHeader.biPlanes=1;
		bi.bmiHeader.biBitCount=bm.bmBitsPixel;
		bi.bmiHeader.biCompression=BI_RGB;
		bi.bmiHeader.biSizeImage=bm.bmWidth*bm.bmHeight*nByte;
		bi.bmiHeader.biClrUsed=0;
		bi.bmiHeader.biClrImportant=0;

		//获取位图数据
		HDC hdc=::GetDC(NULL);
		BYTE* pBits=(BYTE*)new BYTE[bm.bmWidth*bm.bmHeight*nByte];
		::ZeroMemory(pBits,bm.bmWidth*bm.bmHeight*nByte);
		if(!::GetDIBits(hdc,cbmp,0,bm.bmHeight,pBits,&bi,DIB_RGB_COLORS))
		{
			delete pBits;
			pBits=NULL;
		}

		AcGiPixelBGRA32 *colorBlock = new AcGiPixelBGRA32[bm.bmWidth * bm.bmHeight];
		for (int i = 0; i < bm.bmWidth; i++)
		{
			for (int j = 0; j < bm.bmHeight; j++)
			{				
				//colorBlock[i*bm.bmHeight+j].setRGBA(255,255,0,255);
				BYTE r= pBits[i*nByte+j*bm.bmWidthBytes+2];
				BYTE g=pBits[i*nByte+j*bm.bmWidthBytes+1];
				BYTE b=pBits[i*nByte+j*bm.bmWidthBytes+0];
				//如果是黑色,则设置alpha通道
				if(r==0&&g==0&&b==0)
				{
					colorBlock[i+j*bm.bmHeight].setRGBA(r,g,b,0);
				}
				else
				colorBlock[i+j*bm.bmHeight].setRGBA(r,g,b,255);
			}			
		}
		delete pBits;
		pBits=NULL;

		imageSource=new AcGiImageBGRA32(bm.bmWidth, bm.bmHeight, colorBlock);
		acedAddSupplementalCursorImage(imageSource);

		ads_name ss;
		acedSSGet(NULL,NULL,NULL,NULL,ss);

		acedRemoveSupplementalCursorImage(imageSource);
		delete imageSource;
		imageSource=NULL;

截图

参考

https://www.keanw.com/2014/05/adding-a-cursor-badge-in-autocad-2015-using-net.html
http://www.theswamp.org/index.php?topic=58025.msg612684#msg612684
https://forums.autodesk.com/t5/objectarx/what-is-the-magnitude-of-with-in-acgigeometry-image/td-p/4809751