BOOL GetTextMetrics(HDC hdc,LPTEXTMETRIC lptm);可以获得字体信息,并填入TEXTMETRIC结构: typedef struct tagTEXTMETRIC { LONG tmHeight; LONG tmAscent; LONG tmDescent; LONG tmInternalLeading; LONG tmExternalLeading; LONG tmAveCharWidth; LONG tmMaxCharWidth; ... ... ... ... ... ... } TEXTMETRIC; 这个结构中,重要的几个变量其意义见下图: tmInternalLeading 用于显示重音符号;基线上的高度为tmAscent;基线下的高度为tmDescent;tmHeight = tmAscent + tmDescent 被称为单元高度(cell height);tmHeight - tmInternalLeading 被称为字符高度(character height)。 tmExternalLeading是行间距,见下图: CreateFont的第1个参数,如果为正,就是设置单元高度;如果为负,就是设置字符高度。 测试代码(MFC)如下: CClientDC dc(this); LOGFONT logFont; TEXTMETRIC tm; memset(&logFont,0,sizeof(logFont)); logFont.lfCharSet = DEFAULT_CHARSET; logFont.lfHeight = -20; //修改该数值,查看 tm 变量 strcpy(logFont.lfFaceName,"Courier New"); dc.SelectObject(::CreateFontIndirect(&logFont)); dc.GetTextMetrics(&tm); DeleteObject(dc.SelectStockObject(SYSTEM_FIXED_FONT)->m_hObject);

相关推荐
深度强化学习系列(13): 策略梯度(Policy Gradient)
对于DQN来说使用一个网络直接逼近了值函数,最后取得了非常不错的效果, 但是对于一些连续性控制或者动作空间特别大的环境来说,很难全部计算所有的值函数来得到最好的策略,那么直接计算策略的方法就别提出来了。 回顾一下前面几篇,所谓的策略,其实就是状态到动作的映射数学表达为 π:s→aπ:s→a\pi : s \to a, 我们用ττ\tau 表示状态s到最后一个状态的一个序列,表示为: τ:st...
第17章 文字和字体
显示文字是本书所要解决的首要问题,现在我们来研究Microsoft Windows中各种有效字体和字体大小的使用方法以及调整文字的方式。 Windows 3.1发表的TrueType使程序写作者和使用者以灵活的方式处理文字的能力大幅增强。TrueType是轮廓字体技术,由Apple Computer公司和Microsoft公司开发,并被许多字体制造商支持。由于TrueType字体能够连续缩放,并...
Windows 10 下 Nacos 3.0.2 单机版保姆级安装教程(含JDK 17配置与MySQL 8.0连接避坑)
本文提供Windows 10下Nacos 3.0.2单机版的详细安装教程,涵盖JDK 17配置、MySQL 8.0连接优化及生产级安全设置。通过步骤详解和常见问题解决方案,帮助开发者快速完成Nacos的安装与配置,确保服务发现与配置管理的高效运行。
Chapter04 文本输出
今天,我们将一起学习“文本输出”章节,根据标题,
ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片
ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片
AI自动打游戏全攻略:从环境搭建到Agent训练实战
本文系统介绍了AI自动打游戏的技术实现方案,重点解析了强化学习(DQN算法)在贪吃蛇游戏中的应用。文章从技术选型入手,对比了强化学习与计算机视觉两种方案,详细说明了开发环境配置步骤,并深入讲解了DQN模型构建、游戏环境封装、训练优化等核心环节。通过经验回放和目标网络等技术,有效提升了AI的学习效率和稳定性。该方案具有通用性,只需调整参数即可应用于其他简单游戏场景,为开发者实现游戏AI提供了完整的技术路径。
中文字体的FontMetrics解析
中文字体的FontMetrics解析 因行业对字体大小要求严格参考相关规范,因此对通过渲染引擎绘制的文本字体把控严格。 而在Skia/openGL/Qt等主流渲染引擎中,所有设置字体大小(FontSize),都是以英文字体大小作为标准的,准确来说,对应的应该是FontMetrics中的CapHeight作为英文字体高度。 笔者发现在网络上相关资料中,很少有关于中文字符的FontMetrics解析。通过多日研究后,在此详细解析一下中文字体的FontMetrics。 一、FontMetrics标准解析 研究发现
CPU、Core、RISC、ARM等的前世今生
CPU、Core、RISC-V 、ARM、ASIC、FPGA、SOC概念及区分
WINDOW程序设计-渐进
自从3月2日下午4:20又几分钟收到这本经典巨作《window程序设计》我就很兴奋,这本书给我的感觉就想《C++Primer Plus》,或者更好,因为它们两者都兼备了一个共同特点:让你消除基础盲点,解除你从前的疑惑,一切都那么有始有终。 都过了10天了,现在才看到第十章,哎,是有点慢,但是因为没有一味看书,而是基本上把书上所有出现过的程序,以自己理解并独立写出的方式进行着。自己感觉还可以
CAPL通过lookupSignal和DBLookup获取DBC信号的属性信息
CAPL通过lookupSignal和DBLookup获取DBC信号的属性信息以及一些相关问题
高精地图构建:Lidar SLAM与视觉SLAM对比
高精地图构建:Lidar SLAM与视觉SLAM对比 ,人工智能,计算机视觉,大模型,AI,本文围绕高精地图构建,对比 Lidar SLAM 与视觉 SLAM。Lidar SLAM 通过激光获取点云数据,精度高、环境适应性强但成本高、数据量大;视觉 SLAM 利用图像,成本低、信息丰富却受光照影响大、深度获取难。还解析了 SLAM、点云等关键概念,介绍了两者融合趋势、应用案例、技术挑战及未来方向,也给出常见问题解答,为相关领域应用与学习提供参考。
PCB丝印的参数设置
丝印 PCB
文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况
主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。
iOS计算字符串高度
方法一:iOS2.0引入,ios7.0废弃
STM32F407中文手册
STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
ios字符串计算高度总结
1.用xib的话,设置约束的时候 不设置lable的高度即可,高度返回的就是最优高度。 2.用lable代码计算高度 CGFloat getHeightForLableString(NSString *value,CGFloat width,UIFont * font) { UILabel * lable=[[UILabel alloc]initWithFrame:CGR
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
简单计算字符串的高度
计算字符串的高度有很多种,这里写下最常用的简单计算字符串的高度 // // NSString+NSStringExt.h // UIFontSize // // Created by mac on 15/11/14. // Copyright (c) 2015年 叶炯. All rights reserved. // #import <Foundat...
如何处理有换行的字符串,算高度
原来算高度直接使用- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)co
C#如何测量字符串的高度宽度和精确取得字符串的高度宽度
C#如何测量字符串的高度宽度和精确取得字符串的高度宽度 因为MFC中CDC有GetTextExtent()可以获得字符串的高度宽度 像素单位,所以自然想到c#的GDI+的MeasureString,这个同样是测量字符串高度宽度,但是这个不同于CDC,他不适用CDC.GetTextExtent()的适用领域,GDI+ MeasureString会自己处理矩形区域,返回这个矩形区域Si...
Qt获取字符串的高度和宽度
Qt获取字符串的高度和宽度
iOS 指定高度得到可显示文本最大字号,字符串高度、宽度计算
/// 文本字号计算 指定单行字符串高度 /// @param height 返回单行可显示的最大字号 -(CGFloat)fontSizeFromHeight:(CGFloat)height { CGFloat fontSize = 0; for (int i = 0; i < (int)height ; i++) { CGFloat h = [s...
iOS根据字符串计算UITextView高度,以及各种字符串的限定
[UITextView sizeThatFits:(CGSize)size] ,带入自己的textview,调用这个方法,返回一个float类型的高度给你。 也可以用系统的方法 /** @method 获取指定宽度width的字符串在UITextView上的高度 @param textView 待计算的UITextView @param
Swift计算字符串高度,宽度,size方法
计算字符串的高度 swift的原生方法名,基本跟OC一致 OC旧方法, 用了会警告 CGSize size = [self.message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(200, 9999)];OC新方法 CGSize size = [topicModel.content
获取字符串高度或宽度
获取字符串需要显示的控件高度或者是宽度
计算字符串的宽度与高度
//计算字符串的宽度 -(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height { CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSi
计算字符串的宽度、高度
在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法。 1.获取宽度,获取字符串不折行单行显示时所需要的长度 CGSize titleSize = [aString sizeWithFont:font constrainedToSize:CGSizeMake(MAXFLOAT, 30)]; 注:如果想得到宽度的话,size的width
定义一个计算字符串高度的方法
//计算字符串高度的方法-(CGFloat)stringHeight:(NSString *)str{ //设置字符串的属性 NSDictionary *dic=@{NSFontAttributeName:[UIFont systemFontOfSize:17]}; //计算字符串的区域 CGRect rect=[str boundingRectWithSize...
4642



被折叠的 条评论
为什么被折叠?



