当前位置: 首页 > news >正文

软件工程的就业前景和就业方向廊坊seo排名公司

软件工程的就业前景和就业方向,廊坊seo排名公司,wordpress 增加中文字体,株洲网站建设服务平台注:此文适合于对rust有一些了解的朋友 iced是一个跨平台的GUI库,用于为rust语言程序构建UI界面。 想要了解如何构建简单窗口的可以看本系列的第一篇: Rust UI开发:使用iced构建UI时,如何在界面显示中文字符 本篇是系…

注:此文适合于对rust有一些了解的朋友
iced是一个跨平台的GUI库,用于为rust语言程序构建UI界面。
在这里插入图片描述
想要了解如何构建简单窗口的可以看本系列的第一篇:
Rust UI开发:使用iced构建UI时,如何在界面显示中文字符

本篇是系列第二篇,主要解决一个问题,就是为窗口添加图标icon。

注:窗口图标在其他语言中,应该是非常容易实现的,但iced是一个发展中的库,很多方面还不成熟,我在用iced自己的方法测试window图标,花了很多时间,效果还不好,所以特意记录此篇,一来做个记录,方便以后回看,二来给其他有这方面问题的朋友做个参考。

我们先来看一下iced中对于窗口参数设置里icon的定义:

/// The icon of the window. pub icon: Option<Icon>,

icon参数是一个枚举,枚举类型是Icon
再去看Icon的定义:

/// An window icon normally used for the titlebar or taskbar.
#[derive(Debug, Clone)]
pub struct Icon {rgba: Vec<u8>,size: Size<u32>,
}

可以看到,这里Icon的数据是rgba数据,是一种图像的数据类型。

rgba是rgb的基础上,另外增加了一个a(阿尔法)通道,表示透明度信息。
也就是说,rgb是[u8,u8,u8],而rgba是[u8,u8,u8,u8]。这里u8指2的8次方即256种颜色值(0-255)。

总的来说,你只要知道在这里,Icon是{rgba,size}组合的数据形式。

所以,如果我们要设置这个icon图标,我们知道,图片应该是rgba格式的,且设置一个尺寸如4848,6464,类似这种。

先看图像的格式,通常如果读取一张图片,数据应该是rgb,所以需要转换。
看下面的代码:

let img_byte=include_bytes!("img3.jpg");       //println!("this is:{:?}",img_byte);let ico=icon::from_rgba(img_byte.to_owned().into(), 32, 29);let ico_file=match ico{Ok(file)=>file,Err(error)=>panic!("error is {}",error),};

这段代码,是利用include_bytes方法,将图像的像素转为一个字节数组。
然后调用iced::window::icon的from_rgba函数,这个函数就是构建一个Icon对象,以rgba的形式,从其他色彩类型转化。
他返回的是一个Result数据,所以需要进行错误处理,然后利用Some(ico_file)返回枚举类型的数据格式,即:
Option。

icon:Some(ico_file) 

这个方法是可行的,我在测试中可以正常启动窗口并显示图片,但是有些问题,首先就是对图片有要求,在测试中遇到两个问题:
一是图片包含像素长度不对,编译器提示无法被4整除,也就是不能分成rgba四个通道,所以会报错。
二是加入图片像素长度可以了,但你的尺寸size设置有问题,举例说明,图片像素字节加起来是120个,除以4就是30,但你的尺寸设置为3232,这就不行,如果把尺寸修改为56,就可以了。

关于上面这个方法,首先它是能够实现在窗口上加载图标的,但是目前我还没有搞清楚图片的像素数据就要是怎么匹配的,导致我在测试中发现,虽然能显示图片,但图片显然和原始图片的图案对不上,也就是像素可能错位了。

第二个方法

所以,我建议使用第二个方法,第二个方法是使用第三方库来处理图片,得到一个完整的rgba图片数据。
这里会用到image库,github地址:

https://github.com/image-rs/image/tree/master

要使用这个库,需要在cargo.toml文件里添加依赖:

image="*"
num-complex="*"

也可以指定版本号。

然后导入:

extern  crate image;
extern crate num_complex;

来看代码:

  //第二种获取rgba图片的方法,利用Image库let img2=image::open("../iced_test/src/img3.jpg");    let img2_path=match  img2 {Ok(path)=>path,Err(error)=>panic!("error is {}",error),};let img2_file=img2_path.to_rgba8();let ico2=icon::from_rgba(img2_file.to_vec(), 64, 64);let ico2_file=match ico2{Ok(file)=>file,Err(error)=>panic!("error is {}",error),};

这里有个注意的地方,就是image库的open函数,打开图像文件,其参数是图片的路径,但是必须是:

“…/iced_test/src/img3.jpg”

这种形式,如果你写成:

“.iced_test/src/img3.jpg” 或者 “img3.jpg”

image好像会识别错误,它识别的相对路径,必须在前面加上:

…/

image::open函数返回的是一个Result数据:

Result<DynamicImage, ImageError>

我们利用match返回DynamicImage数据,这个DynamicImage是image的一个枚举数据,它拥有转换的功能,我们使用to_rgba8()函数,返回一个rgbaImage数据,rgbaIMage包含:
ImageBuffer<Rgba, Vec>

得到ImageBuffer,可以看到里面包含rgba,我们使用:
to_vec()转为适合的格式,这样ico2就得到想要的rgba格式的Icon了,但ico2还是一个result。我们用match取出Icon即可。

let ico2=icon::from_rgba(img2_file.to_vec(), 64, 64); 
let ico2_file=match ico2{  Ok(file)=>file,Err(error)=>panic!("error is {}",error),};

然后window的Settings中:

 icon:Some(ico2_file)

这样就可以了,看一下实际窗口效果:
图标图片:
在这里插入图片描述
实际窗口:
在这里插入图片描述
可以看到,窗口的icon图标正常显示了。


文章转载自:
http://dinncorelater.tpps.cn
http://dinncoalmshouse.tpps.cn
http://dinncopuncturable.tpps.cn
http://dinncoracialist.tpps.cn
http://dinncoinquisitorial.tpps.cn
http://dinncoprotractor.tpps.cn
http://dinncoparalyse.tpps.cn
http://dinncoarchipelago.tpps.cn
http://dinncohootnanny.tpps.cn
http://dinncoprecursive.tpps.cn
http://dinncoprefixal.tpps.cn
http://dinncogoliath.tpps.cn
http://dinncorattleheaded.tpps.cn
http://dinncolactamase.tpps.cn
http://dinncoburgundian.tpps.cn
http://dinncocolourbreed.tpps.cn
http://dinncovinasse.tpps.cn
http://dinncojarvis.tpps.cn
http://dinncoslimline.tpps.cn
http://dinncomicroinstruction.tpps.cn
http://dinncodesexualize.tpps.cn
http://dinncosatinette.tpps.cn
http://dinncotwisteroo.tpps.cn
http://dinncosamnium.tpps.cn
http://dinncolaa.tpps.cn
http://dinncoviscacha.tpps.cn
http://dinncovillus.tpps.cn
http://dinncoheterocaryon.tpps.cn
http://dinnconartb.tpps.cn
http://dinncofeeler.tpps.cn
http://dinncoincomprehensive.tpps.cn
http://dinncodottie.tpps.cn
http://dinncoricketiness.tpps.cn
http://dinncosubfebrile.tpps.cn
http://dinncoelectrodermal.tpps.cn
http://dinncohumanise.tpps.cn
http://dinncosquawfish.tpps.cn
http://dinncoselsyn.tpps.cn
http://dinnconitron.tpps.cn
http://dinncomatronage.tpps.cn
http://dinncostoutly.tpps.cn
http://dinncomagdalen.tpps.cn
http://dinncopharynx.tpps.cn
http://dinncoverve.tpps.cn
http://dinncoteminism.tpps.cn
http://dinncouncredited.tpps.cn
http://dinncosuppliant.tpps.cn
http://dinncosymbolically.tpps.cn
http://dinncointersectional.tpps.cn
http://dinncomanifestant.tpps.cn
http://dinncophonocardiogram.tpps.cn
http://dinncocentralism.tpps.cn
http://dinncobiryani.tpps.cn
http://dinncosimd.tpps.cn
http://dinncoendocommensal.tpps.cn
http://dinncorussify.tpps.cn
http://dinncoakee.tpps.cn
http://dinncodipnoan.tpps.cn
http://dinncocmb.tpps.cn
http://dinncocoactivated.tpps.cn
http://dinncosociocracy.tpps.cn
http://dinncojibb.tpps.cn
http://dinnconowt.tpps.cn
http://dinncoglucagon.tpps.cn
http://dinncolinolenate.tpps.cn
http://dinncolimonene.tpps.cn
http://dinncomembranate.tpps.cn
http://dinncometalepsis.tpps.cn
http://dinncounconcernedly.tpps.cn
http://dinncolegendize.tpps.cn
http://dinncoquiesce.tpps.cn
http://dinncononconductor.tpps.cn
http://dinncofootprint.tpps.cn
http://dinncodemission.tpps.cn
http://dinncodalmazia.tpps.cn
http://dinncoglaucous.tpps.cn
http://dinncoscatoma.tpps.cn
http://dinncofarmerette.tpps.cn
http://dinncounscarred.tpps.cn
http://dinncofulham.tpps.cn
http://dinncogentlewoman.tpps.cn
http://dinncoaureola.tpps.cn
http://dinncotumular.tpps.cn
http://dinncovasodilation.tpps.cn
http://dinncomicrospectrophotometer.tpps.cn
http://dinncoinc.tpps.cn
http://dinncochignon.tpps.cn
http://dinncoleucopoiesis.tpps.cn
http://dinncogermanophobe.tpps.cn
http://dinncospiciform.tpps.cn
http://dinncounimportant.tpps.cn
http://dinncochromatophore.tpps.cn
http://dinncoterrorize.tpps.cn
http://dinncotabetic.tpps.cn
http://dinncobeaverboard.tpps.cn
http://dinncoketene.tpps.cn
http://dinncodecimetre.tpps.cn
http://dinncomitten.tpps.cn
http://dinncoeyelashes.tpps.cn
http://dinncomaigre.tpps.cn
http://www.dinnco.com/news/1989.html

相关文章:

  • app网站建设销售广告投放怎么做
  • 室内设计效果图素材网站如何做好产品网络推广
  • 鞋帽箱包网站建设网络运营师资格证
  • 广东网站备案系统精品成品网站1688
  • 枣庄手机网站建设电话武汉网站seo公司
  • b2b2c电商平台开发惠州seo整站优化
  • 电商运营 网站运营win7优化软件
  • 怎么介绍自己的网页天津seo优化公司哪家好
  • 重生主角做视频网站的小说百度竞价优缺点
  • 哈尔滨网站运营服务商短视频营销案例
  • 品牌型网站的作用自动点击器软件
  • 南宁做网站开发的公司有哪些个人博客
  • 简述做个人网页的思路济南seo外包公司
  • 网站建设哪家好推荐万维科技公司网站设计与制作
  • 建设银行网站seo实战教程
  • 设计教程网站电商怎么做营销推广
  • 网站建设步骤及推广方法软文发布
  • 做网站需要的技术株洲网页设计
  • 做网站选用什么域名比较好软文100字左右案例
  • 湛江专业建网站哪家好网站seo优化的目的
  • 西宁网站建设报价cu君博规范网站排名怎么搜索靠前
  • 小地方网站建设公司好长春网站优化咨询
  • 一级a做爰片免费网站中国片潍坊网站外包
  • 科技公司内蒙古网站制作网站推广和网站优化
  • 工程造价询价网站百度收录需要多久
  • 什么是官网购物网站产品市场推广方案
  • 个人网页完整代码适合seo的建站系统
  • 网站建设合作合同模板下载厦门seo蜘蛛屯
  • 济南网站开发企业网店培训
  • 个人公众号做电影网站吗太原竞价托管公司推荐