Pillow

Pillow是用于图像处理的库,可用于图像存储、图像显示、图像处理(改变大小、旋转等)。

基本使用

1
2
3
4
5
6
7
8
9
from PIL import Image
im = Image.open("test.png")
print(im.format, im.size, im.mode)
# format 这个属性标识了图像来源。如果图像不是从文件读取它的值就是None。
# size属性是一个二元tuple,包含width和height(宽度和高度,单位都是px)。
# mode 属性定义了图像bands的数量和名称,以及像素类型和深度。常见的modes 有 “L” (luminance) 表示灰度图像, “RGB” 表示真彩色图像, and “CMYK” 表示出版图像。

im.show() # 显示图像

转换文件格式到JPEG

1
2
3
4
5
6
7
8
9
10
11
12
13

from __future__ import print_function
import os, sys
from PIL import Image

for infile in sys.argv[1:]:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
if infile != outfile:
try:
Image.open(infile).save(outfile) # save方法第二个参数可以指定文件格式
except IOError:
print("cannot convert", infile)
Read More

TypeScript入门

在JavaScript的基础上添加了类型系统,可以在编译时检查类型,提高代码的可读性和可维护性。

约定使用 TypeScript 编写的文件以 .ts 为后缀,用 TypeScript 编写 React 时,以 .tsx 为后缀。

1
2
3
4
5
6
#全局安装typescript
npm install -g typescript
#编译
tsc xxx.ts
#运行
node xxx.js

基础

数据类型

JavaScript的类型分为:

Read More

tsconfig.json

如果一个目录下存在 tsconfig.json 文件,那么它意味着这个目录是 TypeScript 项目的根目录。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// configs/base.json
{
"compilerOptions": {}
}

// tsconfig.json

{
"extends": "./configs/base", //继承配置
"compilerOptions": { //编译选项
"incremental": true, //开启增量编译
"tsBuildInfoFile":"./",//指定增量比编译的文件位置
"diagnostics":true,//打印诊断信息
"listFiles":true,//打印编译的文件
"":"",
/* 指定编译版本: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "es6",
/* 指定模块代码的生成方式: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "commonjs", //模版标准
"lib": [], //指定要包含在编译中的库文件
"allowJs": true, //允许编译js文件
"checkJs": true, //检查和报告js文件中的错误
"jsx": "preserve",//指定jsx代码用于的开发环境: preserve、react、react-native
"declaration": false, //是否在编译的时候生成相应的d.ts声明文件。declaration和allowJs不能同时设置为true
"declarationMap": true, //是否在编译的时候生成相应的map声明文件
"sourceMap": true,//
"outFile": "./", //指定输出文件合并为一个文件,只有设置module的值为amd和system模块时才支持这个配置
"outDir": "./", //指定输出文件夹
"rootDir": "./",//指定编译文件的根目录
"composite": true,//是否编译构建引用项目
"removeComments": true,//是否将编译后的文件注释删除掉
"noEmit": true,//不生成编译文件
"importHelpers": true,//是否引入tslib里的复制工具函数,默认为false
"downlevelIteration": true,//当target为“es5”或“es3”时,为“for-of”、“spread”和“destructuring”中的迭代器提供完全支持
"strict": true,//开启所有类型检查
"noImplicitAny": true,//没有设置明确类型会报错
"strictNullChecks": true, //为true时,null和undefined值不能赋值给非这两种类型的值,别的类型的值也不能赋给他们,除了any类型,还有个例外就是undefined可以赋值给void类型
"baseUrl": "/",//设置解析非相对模块名称的基本目录,
"paths": {//基于baseUrl的路径映射
"":"",
},
/* 指定模块的解析策略: node、classic */
/* 若未指定,那么在使用了 --module AMD | System | ES2015 时的默认值为 Classic,其它情况时则为 Node */
"moduleResolution": "",
"": "",
},
/* 指定需要编译的单个文件列表 */
"files": [

],
"include": [], //指定要编译的路径列表
"exclude": [],//要排除的不编译的文件/文件夹列表


}

参考

Read More

调试方式

使用流程

  1. 启动Metro服务 npm start,可以设置不同端口号npm run start –verbose – –port 8082
  2. 启动项目npm run android
  3. 打开开发者菜单,点击Debug,如果没有打开浏览器调试窗口,可尝试在Settings页面配置IP:Port,设置端口转发
Read More