Kanzi编程基础3 - 图片读取与显示
Kanzi开发的时候会遇到需要从外部读取图片的情况。Kanzi2.8版本和3.3版本读取方法稍有不同,我们先看看2.8版本的api。
【2.8版本】
1)首先要从文件中读取一张图片
struct KzcImage* img;
kzcImageLoadFile(kzaApplicationGetSystemMemoryManager(application),"1.png",& img);
2)把文件中读取到的图片转成Texture
KzuImageTexture* texture;
kzuImageTextureCreateFromImage(resMgr, "FileTexture",
img, KZU_TEXTURE_FILTER_BILINEAR, KZU_TEXTURE_WRAP_CLAMP, 0.0f, &texture);
或者从内存数据中创建一个Texture:
kzuImageTextureCreateFromMemory(resourceManger,name, KZU_TEXTURE_CHANNELS_RGB, img.width(), img.height(), img.bits(), KZU_TEXTURE_FILTER_BILINEAR, KZU_TEXTURE_WRAP_CLAMP, &imageTexture);
其中resourceManger是一个ResourceManger对象,name为Texture的名称,KZU_TEXTURE_CHANNELS_RGB为创建的图像模式,bits()为图片数据,最终创建到imageTexture中。
3)创建之后转成resource并赋给plane节点
struct KzuResource* out_resource; out_resource = kzuImageTextureToResource(texture); kzuObjectNodeSetResourceIDResourceProperty(planeNode,KZU_PROPERTY_TYPE_TEXTURE,out_resource); kzuObjectNodeSetIntProperty(m_planeNode, KZU_PROPERTY_TYPE_BLEND_MODE, ); kzuResourceRelease(out_resource);
【3.3版本】
3.3可以参考kanzi安装目录下的 virtual listbox的例子。
下面是例子中的关键代码:
if (m_itemInfo->m_objectNode && m_image)
{
Domain* domain = m_itemGenerator->m_listBox->getDomain(); // Create texture from image. If the image data format is correct, this shouldn't use any memory manager.
// Image texture will own the image so no need to delete it manually.
TextureSharedPtr texture = Texture::create(domain, m_image, Texture::CreateFlagClampAddress);
m_itemInfo->m_objectNode->setProperty(StandardMaterial::TextureProperty, texture); // Adjust size of plane for displaying the image.
Node3DSharedPtr imagePlaneNode = m_itemInfo->m_objectNode->lookupNode<Node3D>("Stack Layout/Plane"); kzUint height = kzcImageGetHeight(m_image);
kzUint width = kzcImageGetWidth(m_image);
float aspect = width * 1.0f / height; kzFloat widthFactor = aspect;
kzFloat heightFactor = 1.0f; if(aspect > 1.0f)
{
widthFactor = 1.0f;
heightFactor = 1.0f / aspect;
} imagePlaneNode->setLayoutTransformation(Matrix4x4::createScale(Vector3(widthFactor, heightFactor, 1.0f))); // Ownership of image was transferred to the texture.
m_image = ;
} // Remove task.
m_itemGenerator->m_tasksByItems.erase(m_itemInfo);
3.3版本的代码暂时还没有分析,待补充……
Kanzi编程基础3 - 图片读取与显示的更多相关文章
- Kanzi编程基础2 - Kanzi节点读取和属性设置
UI设计师在Kanzi studio把Kanzi的节点做好后,就要编码读取这些节点并根据实际功能去控制刷新它. Kanzi读取节点的api发生过很多次变化,从2.7.2.8到3.0,每次变化都比较大, ...
- Kanzi编程基础1 - 定时器Timer
Kanzi虽然发生了比较多的版本更迭,api也发生了很多变化,但定时器的头文件一直都在一个地方:#include "user/include/user/ui/message/kzu_mess ...
- OpenCV笔记(1)(图片读取与现实、色彩空间、基础运算、均值方差、逻辑运算、泛洪填充、均值中值及自定义平滑)
一.图片读取和显示 import cv2 as cv # 图片读取cv.imread(img_path) car_img = cv.imread("car1.png") # 图片显 ...
- 图像的读取,显示与保存(基于skimage模块)
一 skiamge模块 skimage包的全称是scikit-image SciKit (toolkit for SciPy) ,它对scipy.ndimage进行了扩展,提供了更多的图片处理功能.它 ...
- FileReader:读取本地图片文件并显示
最近忙得比狗还惨,导致长时间没能更新文章,真心对不住啊.抽空整理了下关于在页面上读取和显示本地图片的实例文章,本文通过实例讲解如何使用支持FileReader浏览器的用户将能够通过一个file inp ...
- spring从服务器磁盘读取图片,然后显示于前端页面上
需求是,前台通过传参,确定唯一图片,然后后台在服务器磁盘中读取该图片,然后显示于前台页面上. 后台代码: @RequestMapping("unit/bill/showeinvoice&qu ...
- [转]opengl入门例题(读取bmp图片,并显示)
#include<gl/glut.h> #define FileName "bliss.bmp" static GLint imagewidth; static GLi ...
- python中用opencv读取并显示图片
一.读取并显示图片: import matplotlib.pyplot as plt # plt 用于显示图片 import matplotlib.image as mpimg # mpimg 用于读 ...
- java IO流读取图片供前台显示
最近项目中需要用到IO流来读取图片以提供前台页面展示,由于以前一直是用url路径的方式进行图片展示,一听说要项目要用IO流读取图片感觉好复杂一样,但任务下达下来了,做为程序员只有选择去执行喽,于是找了 ...
随机推荐
- 奥威软件Speed-BI荣获2016年度中国大数据最佳云平台奖
(原文转自:http://www.powerbi.com.cn/page110?article_id=210) 2016年12月16日,“科技原力觉醒,引领创新巅峰”—2016创新影响力年会暨国家产业 ...
- docker 学习
vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/docker daemon --bip=172.18.42.1/16 --r ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 错误解决
今天在做LNMP的时候,启动nginx服务,无法开启,导致网页打不开.把服务从起一下发现提示错误如下: Starting nginx: nginx: [emerg] bind() to 0.0.0.0 ...
- word嵌入图片部分被段落遮挡
这是因为图片所在段落的行距被设置为固定行距造成的 解决办法: 把图片所在段落的行距改为单倍行距
- Virtualbox虚拟机配置CentOS7.0静态网络
1.首先在Virtualbox下将网络设置为Bridged Adapter,此项设置可以使本机与虚拟机进行互访,而NAT模式只能进行单项访问: 2.先切换到root,配置网卡信息需要用到root,然后 ...
- 如何把Excel中的某列数值如何转换成文本格式,且兼容性最好?
假设要把下方A列数值变成文本格式.有多种方法,其中下方的方法兼容性最好: 第一步:选择 A 列,然后,运行菜单 数据/分列... 命令,如下图: 第二步:默认 下一步: 第三步:默认 下一步: 第四步 ...
- Linux服务器ftp命令找不到
ftp commond not find 先用命令rpm -q vsftpd检查是否安装了ftp服务器 若显示vsftpd-2.2.2-11.el6_4.1.x86_64这样的信息,说明FTP服务器已 ...
- Design and Analysis of Algorithms_Brute Froce
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- 注册Jdbc驱动程序的三种方式
注册Jdbc驱动程序的三种方式 1. Class.forName("com.mysql.jdbc.Driver"); 2. DriverManager.registerDriver ...
- 创建支持eclipse的多模块maven项目
通过maven可以创建多个关联模块的项目(Multiple Module Projects).由一个总的模块,下面包含多个子模块(子模块还可以包含子模块). 这种maven功能能支持大型的项目构建,往 ...