CvFont的定义和操作

程序用用到的一些字体操作和设置,贴出来备个份,方便查阅。


主要是cvGetTextSize(text, &font, &text_size, &baseline);


cvPoint(2,text_size.height+baseline)


这样写出的字才对齐得更好些。



CvPoint pt;

pt.x = point.x - text_size.width/2; //这样的设置为字体(左右)居中对齐


pt.y = point.y + (text_size.height+baseline)/2; //这样的设置为字体(上下)居中对齐

if(i==0) pt.y = (AVIFRAME_COLORBAR_HEIGHT-AVIFRAME_BAR_HEIGHT)+10; //设置字体输出的具体位置


else if(i==portion) pt.y=AVIFRAME_COLORBAR_HEIGHT-5;
//Stage x
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_DUPLEX ,1.0f,1.0f,0,1,CV_AA);

char text[20];
sprintf(text,"Stage%d",nIndex);
CvSize text_size;
int baseline;
cvGetTextSize(text, &font, &text_size, &baseline);
cvPutText(aviFrame,text,cvPoint(20,text_size.height+baseline),&font, CV_RGB(255,0,0));

//makeTilte
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_TRIPLEX,0.35f,0.7f,0,1,CV_AA);
char* text="Major Strain[%]";
CvSize text_size;
int baseline;
cvGetTextSize(text, &font, &text_size, &baseline);
cvPutText(colorbar,text,cvPoint(2,text_size.height+baseline),&font,CV_RGB(0,0,0));

//写刻度值
double gap=(maxLimit-minLimit)/double(portion);
CvPoint pt;
char buffer[30];
double value;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX ,0.5f,0.5f,0,1,CV_AA);
for(i=0;i<=portion;i++)
{
value = (maxLimit- i*gap)*100;
sprintf(buffer,"%4.2f",value);
pt.x=AVIFRAME_BAR_WIDTH+10;
if(i==0) pt.y = (AVIFRAME_COLORBAR_HEIGHT-AVIFRAME_BAR_HEIGHT)+10;
else if(i==portion) pt.y=AVIFRAME_COLORBAR_HEIGHT-5;
else pt.y=i*AVIFRAME_BAR_HEIGHT/portion+(AVIFRAME_COLORBAR_HEIGHT-AVIFRAME_BAR_HEIGHT);
cvPutText(colorbar,buffer,pt,&font, CV_RGB(0,0,0));
}

void CYnPlot::MakeLabelImage(IplImage** pImage,const char* text,double scale)
{
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_TRIPLEX ,0.5f*scale,0.5f*scale,0,1,CV_AA);

CvSize text_size;
cvGetTextSize(text, &font, &text_size, NULL);

if (*pImage) cvReleaseImage(pImage);
*pImage = cvCreateImage(cvSize(text_size.width+5,text_size.height+10),8,3);
cvSet(*pImage,CV_RGB(255,255,255));
cvPutText(*pImage,text,cvPoint(2,text_size.height+3),&font, CV_RGB(0,0,0));
}

void CYnPlot::MakeTitleImage(IplImage** pImage,const char* text)
{
CvFont font;
cvInitFont(&font,CV_FONT_HERSHEY_TRIPLEX ,0.7f,0.7f,0,1,CV_AA);

CvSize text_size;
cvGetTextSize(text, &font, &text_size, NULL);

if (*pImage) cvReleaseImage(pImage);
*pImage = cvCreateImage(cvSize(text_size.width+5,text_size.height+10),8,3);
cvSet(*pImage,CV_RGB(255,255,255));
cvPutText(*pImage,text,cvPoint(2,text_size.height+3),&font, CV_RGB(0,0,0));
}

CvFont font;
CvSize text_size;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX ,0.35f,0.35f,0,1,CV_AA);

CvFont font;
double hscale = 0.2f*_pointSize;
cvInitFont(&font,CV_FONT_HERSHEY_TRIPLEX ,hscale,hscale,0,1,CV_AA);

CvSize text_size;
int baseline;
cvGetTextSize(text, &font, &text_size,&baseline);
CvPoint pt;
pt.x = point.x - text_size.width/2;
pt.y = point.y + (text_size.height+baseline)/2;
cvPutText(m_pPlotImage,text,pt,&font, color);

CvFont font;
double hscale = 0.2f*_pointSize;
cvInitFont(&font,CV_FONT_HERSHEY_TRIPLEX ,hscale,hscale,0,1,CV_AA);

CvSize text_size;
int baseline;
cvGetTextSize(text, &font, &text_size,&baseline);
CvPoint pt;
pt.x = point.x - text_size.width/2;
pt.y = point.y + (text_size.height+baseline)/2;
cvPutText(m_pPlotImage,text,pt,&font, color);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值