首页 文章 精选 留言 我的

精选列表

搜索[工具模块],共10000篇文章
优秀的个人博客,低调大师

[雪峰磁针石博客]selenium自动化测试工具python笔试面试项目实战5键盘操作

说明 本文参考答案基于Chrome,分辨率1920*1080,在其他环境表现可能会不同。本文代码地址 参考书籍下载: Learning Selenium Testing Tools with Python-2014.pdf Selenium自动化测试 基于 Python 语言 - 2018.pdf 上机实操: 在新的TAB打开连接 打开:https://china-testing.github.io/ 选择"数据分析"栏目的文章 按住"Ctrl+TAB"选择"python"栏目的文章 切换到新的标签"python" 关闭新的标签"python" 关闭浏览器 参考答案 #!/usr/bin/python3 # -*- coding: utf-8 -*- # 讨论钉钉免费群21745728 qq群144081101 567351477 # CreateDate: 2018-10-17 import time from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("https://china-testing.github.io/") driver.implicitly_wait(30) driver.maximize_window() element = driver.find_element_by_link_text('数据分析') element.click() time.sleep(3) element = driver.find_element_by_link_text('python') ActionChains(driver).key_down(Keys.CONTROL).click(element).key_up( Keys.CONTROL).perform() time.sleep(3) driver.switch_to.window(driver.window_handles[1]) time.sleep(3) driver.close() # 关闭当前TAB time.sleep(3) driver.quit() 面试问答 driver.quit() 和 driver.close()有什么区别? 2.selenium中按下和松开键如何表示? 3.简述ActionChains类的作用? 上机实操: 验证悬浮提示内容 打开:http://jqueryui.com/tooltip/ 鼠标移动到上图的"Your age:" 确认悬浮提示内容为'We ask for your age only for statistical purposes.' 关闭浏览器 参考答案 #!/usr/bin/python3 # -*- coding: utf-8 -*- # 讨论钉钉免费群21745728 qq群144081101 567351477 # CreateDate: 2018-10-17 import unittest import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions from selenium.webdriver.common.action_chains import ActionChains class ToolTipTest (unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://jqueryui.com/tooltip/") self.driver.implicitly_wait(30) self.driver.maximize_window() def test_tool_tip(self): driver = self.driver frame_elm = driver.find_element_by_class_name('demo-frame') driver.switch_to.frame(frame_elm) time.sleep(3) age_field = driver.find_element_by_id('age') ActionChains(self.driver).move_to_element(age_field).perform() time.sleep(3) tool_tip_elm = WebDriverWait(self.driver, 10).until( expected_conditions.visibility_of_element_located(( By.CLASS_NAME, 'ui-tooltip-content'))) # verify tooltip message self.assertEqual('We ask for your age only for statistical purposes.', tool_tip_elm.text) time.sleep(3) def tearDown(self): self.driver.close() if __name__ == '__main__': unittest.main(verbosity=2) 面试问答 1.move_to_element()有什么用途? 上机实操: 双击改变颜色 打开:http://api.jquery.com/dblclick/ 双击上图蓝色的框,把颜色该变成黄色 参考答案 #!/usr/bin/python3 # -*- coding: utf-8 -*- # 讨论钉钉免费群21745728 qq群144081101 567351477 # CreateDate: 2018-10-18 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import unittest class DoubleClickTest (unittest.TestCase): URL = 'http://api.jquery.com/dblclick/' def setUp(self): self.driver = webdriver.Chrome() self.driver.get(self.URL) self.driver.maximize_window() def test_double_click(self): driver = self.driver frame = driver.find_element_by_tag_name('iframe') driver.switch_to.frame(frame) box = driver.find_element_by_tag_name('div') # verify color is Blue self.assertEqual('rgba(0, 0, 255, 1)', box.value_of_css_property('background-color')) ActionChains(driver).move_to_element( driver.find_element_by_tag_name('body')).perform() ActionChains(driver).double_click(box).perform() # verify Color is Yellow self.assertEqual('rgba(255, 255, 0, 1)', box.value_of_css_property('background-color')) def tearDown(self): self.driver.close() if __name__ == '__main__': unittest.main(verbosity=2) 面试问答 1.double_click()有什么用途? 2.rgba的含义? 上机实操: 在新的TAB打开连接 打开:http://jqueryui.com/resources/demos/droppable/default.html 拖动左边的框到右边 参考答案 #!/usr/bin/python3 # -*- coding: utf-8 -*- # 讨论钉钉免费群21745728 qq群144081101 567351477 # CreateDate: 2018-10-18 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains import unittest class DragAndDropTest (unittest.TestCase): URL = 'http://jqueryui.com/resources/demos/droppable/default.html' def setUp(self) : self.driver = webdriver.Chrome() self.driver.get(self.URL) self.driver.maximize_window() def test_drag_and_drop(self): driver = self.driver source = driver.find_element_by_id('draggable') target = driver.find_element_by_id('droppable') ActionChains(self.driver).drag_and_drop(source, target).perform() self.assertEqual('Dropped!', target.text) def tearDown(self): self.driver.close() if __name__ == '__main__': unittest.main(verbosity=2) 面试问答 1.drag_and_drop()有什么用途? 参考资料 讨论 钉钉群21745728 qq群144081101 567351477 本文最新版本地址 本文涉及的python测试开发库 谢谢点赞! 本文相关海量书籍下载

优秀的个人博客,低调大师

八月新增开源项目:假装自己是图形界面的 Git 命令行工具

每月新增开源项目。顾名思义,每月更新一期。我们会从社区上个月新收录的开源项目中,挑选出有价值的、有用的、优秀的、或者好玩的开源项目来和大家分享。数量不多,但我们力求推荐的都是精品。目前这些开源项目主要来源于编辑们的搜集和用户的投递,所以如果你有更好的开源项目推荐,欢迎积极投递。 戳这里查看投递软件的正确姿势 >>>https://www.oschina.net/question/2918182_2266982。 Web Forever —— Web 开发项目推荐 facebookincubator/fizzFizz ——C++ 14 实现的 TLS 1.3 标准库 TLS 1.3 已正式发布,而且主流浏览器也已经提供了对其的支持。开发者对于 TLS 1.3 就更不能忽视了。Fizz 是由 Facebook 开源的 TLS 1.3 标准库,旨在帮助开发者实现 TLS 1.3 协议以及所有推荐的安全性和性能相关配置。 Fizz 使用 C++ 14 进行编写,它是一个可靠且高性能的 TLS 库,具有现代 TLS 库所需的一些重要功能。支持所有主要的握手模式、强大的加密算法和性能优化,旨在以超过 10% 的速度安全地传输数据。除了 TLS 1.3 附带的增强功能外,Fizz 还为中间件握手失败提供了改进的解决方案,默认支持异步 I/O,并且可以处理分散/收集 I/O 以消除对额外数据副本的需求。 Facebook 与 IETF 长期密切合作,在增加 TLS 安全性的同时,也没有忽略性能的重要性,过去他们使用了自定义的零协议(Zero Protocol),现在 Facebook 已经用 Fizz 取代了其旧的零协议,Fizz 现在负责每天在 Facebook 上获得的数万亿连接。 resilience4j/resilience4jResilience4j —— 面向 Java 8 和函数式编程的轻量级容错组件库 Resilience4j 是一个轻量级的容错组件,其灵感来自于Hystrix,但主要为 Java 8 和函数式编程所设计。轻量级体现在其只用Vavr库(前身是 Javaslang),没有任何外部依赖。而 Hystrix 依赖了 Archaius ,Archaius 本身又依赖很多第三方包,例如 Guava、Apache Commons Configuration 等。 限速组件架构: alibaba/noformnoForm—— 阿里开源的基于 React 的表单解决方案 表单在前端可谓是非常常见的场景,而且通常需要花费开发非常多的时间来处理各种复杂的逻辑。特别是在企业中后台的业务中,存在着大量的表单,比如客户的订单,投诉的问题单,服务跟进过程每个流程的流转。凡是存在用户输入的地方都存在着各种各样的表单,字段或多或少,逻辑或繁或简。需求一旦变动,造成的代码变动(代码量或者逻辑分支)可能是非常恐怖的。比如当A字段选择了x的时候,增加B,C,D三个字段。相信这是非常多前端开发非常苦恼的问题。 NoForm 是阿里巴巴外综服前端团队在外综服(外贸综合服务)场景下,经过长期的思考和打磨产出的一款基于 React 的表单解决方案。可能有人不理解,可能会问:表单嘛,能有多复杂? 可能你从没见过一个表单需要填写150+个字段。可能你也没有见过一个表单实际是由10+个子表单组合出来的。可能你也没见过一个表单的字段是后端动态配置的。NoForm 从解决业务复杂性的角度出发,找到了几个抓手,将表单方案进行了优化和开源。 NoForm 将表单操作到抽象到核心,从此数据(data)的管理和视图(view)分离开来,权责分明。 通过内置的状态管理方案,能够快速切换同一表单的不同状态,新建和详情不再需要维护多份代码。 通过定制组件接入标准,方便接入社区优秀的组件库,减少开发者重复劳动的时间。 请访问Simple Demo获取更好的试用体验。 Funny OSS — 有趣的开源软件 jesseduffield/lazygit——用于 Git 命令行的简单终端 UI lazygit 是一个用于 Git 命令行的简单终端 UI,使用 Go 语言编写,用到了 gocui 库,目的是在命令行提供 Git 的图形界面。 相信不少朋友看到这里会对这个所谓的“图形界面”嗤之以鼻,因为这个“图形界面”依然需要通过命令行进行控制,毕竟程序员们想的是,如果我懂命令行早就用命令行操作了,还会在乎有没有界面吗?话虽如此,这个项目还是很受欢迎的,在 GitHub 上的 star 数早已超过一万。各位感兴趣的话不妨安装来把玩一下。 Deep Learning —— 深度学习项目推荐 oracle/graphpipeGraphPipe——深度学习模型部署框架 机器学习有望改变行业现状。但是,它在企业中的应用速度比大家预期的要慢,因为这些组织很难自己部署和管理机器学习技术。部分挑战是机器学习模型通常使用定制技术进行训练和部署,从而难以跨服务器或不同部门进行模型的部署。 为此,甲骨文希望通过开源且高性能的标准网络协议来传输张量数据(tensor data) —— 这样的一种技术手段来解决上述挑战。这项新标准,甲骨文称之为 GraphPipe,可使企业更容易从任何框架部署和查询机器学习模型。 官方对 GraphPipe 的解释为,这是一种协议和软件集合,旨在简化机器学习模型部署并将其与特定于框架的模型实现分离。 本期的推荐到此结束,更多有趣有料的开源软件尽在开源中国社区等你来发现~! 最后,欢迎关注【开源中国】微信公众号(ID: oschina2013),获取更多技术干货和第一手开源资讯

优秀的个人博客,低调大师

[雪峰磁针石博客]数据分析工具pandas快速入门教程2-pandas数据结构

创建数据 Series和python的列表类似。DataFrame则类似值为Series的字典。 create.py #!/usr/bin/env python3 # -*- coding: utf-8 -*- # create.py import pandas as pd print("\n\n创建序列Series") s = pd.Series(['banana', 42]) print(s) print("\n\n指定索引index创建序列Series") s = pd.Series(['Wes McKinney', 'Creator of Pandas'], index=['Person', 'Who']) print(s) # 注意:列名未必为执行的顺序,通常为按字母排序 print("\n\n创建数据帧DataFrame") scientists = pd.DataFrame({ ' Name': ['Rosaline Franklin', 'William Gosset'], ' Occupation': ['Chemist', 'Statistician'], ' Born': ['1920-07-25', '1876-06-13'], ' Died': ['1958-04-16', '1937-10-16'], ' Age': [37, 61]}) print(scientists) print("\n\n指定顺序(index和columns)创建数据帧DataFrame") scientists = pd.DataFrame( data={'Occupation': ['Chemist', 'Statistician'], 'Born': ['1920-07-25', '1876-06-13'], 'Died': ['1958-04-16', '1937-10-16'], 'Age': [37, 61]}, index=['Rosaline Franklin', 'William Gosset'], columns=['Occupation', 'Born', 'Died', 'Age']) print(scientists) 执行结果: $ ./create.py 创建序列Series 0 banana 1 42 dtype: object 指定索引index创建序列Series Person Wes McKinney Who Creator of Pandas dtype: object 创建数据帧DataFrame Name Occupation Born Died Age 0 Rosaline Franklin Chemist 1920-07-25 1958-04-16 37 1 William Gosset Statistician 1876-06-13 1937-10-16 61 指定顺序(index和columns)创建数据帧DataFrame Occupation Born Died Age Rosaline Franklin Chemist 1920-07-25 1958-04-16 37 William Gosset Statistician 1876-06-13 1937-10-16 61 Series 官方文档:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html Series的属性 属性 描述 loc 使用索引值获取子集 iloc 使用索引位置获取子集 dtype或dtypes 类型 T 转置 shape 数据的尺寸 size 元素的数量 values ndarray或类似ndarray的Series Series的方法 方法 描述 append 连接2个或更多系列 corr 计算与其他Series的关联 cov 与其他Series计算协方差 describe 计算汇总统计 drop duplicates 返回一个没有重复项的Series equals Series是否具有相同的元素 get values 获取Series的值,与values属性相同 hist 绘制直方图 min 返回最小值 max 返回最大值 mean 返回算术平均值 median 返回中位数 mode(s) 返回mode(s) replace 用指定值替换系列中的值 sample 返回Series中值的随机样本 sort values 排序 to frame 转换为数据帧 transpose 返回转置 unique 返回numpy.ndarray唯一值 series.py #!/usr/bin/python3 # -*- coding: utf-8 -*- # CreateDate: 2018-3-14 # series.py import pandas as pd import numpy as np scientists = pd.DataFrame( data={'Occupation': ['Chemist', 'Statistician'], 'Born': ['1920-07-25', '1876-06-13'], 'Died': ['1958-04-16', '1937-10-16'], 'Age': [37, 61]}, index=['Rosaline Franklin', 'William Gosset'], columns=['Occupation', 'Born', 'Died', 'Age']) print(scientists) # 从数据帧(DataFrame)获取的行或者列为Series first_row = scientists.loc['William Gosset'] print(type(first_row)) print(first_row) # index和keys是一样的 print(first_row.index) print(first_row.keys()) print(first_row.values) print(first_row.index[0]) print(first_row.keys()[0]) # Pandas.Series和numpy.ndarray很类似 ages = scientists['Age'] print(ages) # 统计,更多参考http://pandas.pydata.org/pandas-docs/stable/basics.html#descriptive-statistics print(ages.mean()) print(ages.min()) print(ages.max()) print(ages.std()) scientists = pd.read_csv('../data/scientists.csv') ages = scientists['Age'] print(ages) print(ages.mean()) print(ages.describe()) print(ages[ages > ages.mean()]) print(ages > ages.mean()) manual_bool_values = [True, True, False, False, True, True, False, False] print(ages[manual_bool_values]) print(ages + ages) print(ages * ages) print(ages + 100) print(ages * 2) print(ages + pd.Series([1, 100])) # print(ages + np.array([1, 100])) 会报错,不同类型相加,大小一定要一样 print(ages + np.array([1, 100, 1, 100, 1, 100, 1, 100])) # 排序: 默认有自动排序 print(ages) rev_ages = ages.sort_index(ascending=False) print(rev_ages) print(ages * 2) print(ages + rev_ages) 执行结果 $ python3 series.py Occupation Born Died Age Rosaline Franklin Chemist 1920-07-25 1958-04-16 37 William Gosset Statistician 1876-06-13 1937-10-16 61 <class 'pandas.core.series.Series'> Occupation Statistician Born 1876-06-13 Died 1937-10-16 Age 61 Name: William Gosset, dtype: object Index(['Occupation', 'Born', 'Died', 'Age'], dtype='object') Index(['Occupation', 'Born', 'Died', 'Age'], dtype='object') ['Statistician' '1876-06-13' '1937-10-16' 61] Occupation Occupation Rosaline Franklin 37 William Gosset 61 Name: Age, dtype: int64 49.0 37 61 16.97056274847714 0 37 1 61 2 90 3 66 4 56 5 45 6 41 7 77 Name: Age, dtype: int64 59.125 count 8.000000 mean 59.125000 std 18.325918 min 37.000000 25% 44.000000 50% 58.500000 75% 68.750000 max 90.000000 Name: Age, dtype: float64 1 61 2 90 3 66 7 77 Name: Age, dtype: int64 0 False 1 True 2 True 3 True 4 False 5 False 6 False 7 True Name: Age, dtype: bool 0 37 1 61 4 56 5 45 Name: Age, dtype: int64 0 74 1 122 2 180 3 132 4 112 5 90 6 82 7 154 Name: Age, dtype: int64 0 1369 1 3721 2 8100 3 4356 4 3136 5 2025 6 1681 7 5929 Name: Age, dtype: int64 0 137 1 161 2 190 3 166 4 156 5 145 6 141 7 177 Name: Age, dtype: int64 0 74 1 122 2 180 3 132 4 112 5 90 6 82 7 154 Name: Age, dtype: int64 0 38.0 1 161.0 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN dtype: float64 0 38 1 161 2 91 3 166 4 57 5 145 6 42 7 177 Name: Age, dtype: int64 0 37 1 61 2 90 3 66 4 56 5 45 6 41 7 77 Name: Age, dtype: int64 7 77 6 41 5 45 4 56 3 66 2 90 1 61 0 37 Name: Age, dtype: int64 0 74 1 122 2 180 3 132 4 112 5 90 6 82 7 154 Name: Age, dtype: int64 0 74 1 122 2 180 3 132 4 112 5 90 6 82 7 154 Name: Age, dtype: int64 数据帧(DataFrame) DataFrame是最常见的Pandas对象,可认为是Python存储类似电子表格的数据的方式。Series多常见功能都包含在DataFrame中。 子集的方法 注意ix现在已经不推荐使用。 DataFrame常用的索引操作有: 方式 描述 df[val] 选择单个列 df [[ column1, column2, ... ]] 选择多个列 df.loc[val] 选择行 loc [[ label1 , label2 ,...]] | 选择多行 |df.loc[:, val] | 基于行index选择列 | df.loc[val1, val2] | 选择行列 |df.iloc[row number] | 基于行数选择行 | iloc [[ row1, row2, ...]] Multiple rows by row number | 基于行数选择多行 |df.iloc[:, where] | 选择列 | df.iloc[where_i, where_j] | 选择行列 |df.at[label_i, label_j] | 选择值 |df.iat[i, j] | 选择值 |reindex method | 通过label选择多行或列 |get_value, set_value | 通过label选择耽搁行或列 df[bool] | 选择行df [[ bool1, bool2, ...]] | 选择行df[ start :stop: step ] | 基于行数选择行 #!/usr/bin/python3 # -*- coding: utf-8 -*- # CreateDate: 2018-3-31 # df.py import pandas as pd import numpy as np scientists = pd.read_csv('../data/scientists.csv') print(scientists[scientists['Age'] > scientists['Age'].mean()]) first_half = scientists[: 4] second_half = scientists[ 4 :] print(first_half) print(second_half) print(first_half + second_half) print(scientists * 2) 执行结果 #!/usr/bin/python3 # -*- coding: utf-8 -*- # df.py import pandas as pd import numpy as np scientists = pd.read_csv('../data/scientists.csv') print(scientists[scientists['Age'] > scientists['Age'].mean()]) first_half = scientists[: 4] second_half = scientists[ 4 :] print(first_half) print(second_half) print(first_half + second_half) print(scientists * 2) 执行结果 $ python3 df.py Name Born Died Age Occupation 1 William Gosset 1876-06-13 1937-10-16 61 Statistician 2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse 3 Marie Curie 1867-11-07 1934-07-04 66 Chemist 7 Johann Gauss 1777-04-30 1855-02-23 77 Mathematician Name Born Died Age Occupation 0 Rosaline Franklin 1920-07-25 1958-04-16 37 Chemist 1 William Gosset 1876-06-13 1937-10-16 61 Statistician 2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse 3 Marie Curie 1867-11-07 1934-07-04 66 Chemist Name Born Died Age Occupation 4 Rachel Carson 1907-05-27 1964-04-14 56 Biologist 5 John Snow 1813-03-15 1858-06-16 45 Physician 6 Alan Turing 1912-06-23 1954-06-07 41 Computer Scientist 7 Johann Gauss 1777-04-30 1855-02-23 77 Mathematician Name Born Died Age Occupation 0 NaN NaN NaN NaN NaN 1 NaN NaN NaN NaN NaN 2 NaN NaN NaN NaN NaN 3 NaN NaN NaN NaN NaN 4 NaN NaN NaN NaN NaN 5 NaN NaN NaN NaN NaN 6 NaN NaN NaN NaN NaN 7 NaN NaN NaN NaN NaN Name Born \ 0 Rosaline FranklinRosaline Franklin 1920-07-251920-07-25 1 William GossetWilliam Gosset 1876-06-131876-06-13 2 Florence NightingaleFlorence Nightingale 1820-05-121820-05-12 3 Marie CurieMarie Curie 1867-11-071867-11-07 4 Rachel CarsonRachel Carson 1907-05-271907-05-27 5 John SnowJohn Snow 1813-03-151813-03-15 6 Alan TuringAlan Turing 1912-06-231912-06-23 7 Johann GaussJohann Gauss 1777-04-301777-04-30 Died Age Occupation 0 1958-04-161958-04-16 74 ChemistChemist 1 1937-10-161937-10-16 122 StatisticianStatistician 2 1910-08-131910-08-13 180 NurseNurse 3 1934-07-041934-07-04 132 ChemistChemist 4 1964-04-141964-04-14 112 BiologistBiologist 5 1858-06-161858-06-16 90 PhysicianPhysician 6 1954-06-071954-06-07 82 Computer ScientistComputer Scientist 7 1855-02-231855-02-23 154 MathematicianMathematician 修改列 #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: xurongzhong#126.com wechat:pythontesting qq:37391319 # qq群:144081101 591302926 567351477 # CreateDate: 2018-06-07 # change.py import pandas as pd import numpy as np import random scientists = pd.read_csv('../data/scientists.csv') print(scientists['Born'].dtype) print(scientists['Died'].dtype) print(scientists.head()) # 转为日期 参考:https://docs.python.org/3.5/library/datetime.html born_datetime = pd.to_datetime(scientists['Born'], format='%Y-%m-%d') died_datetime = pd.to_datetime(scientists['Died'], format='%Y-%m-%d') # 增加列 scientists['born_dt'], scientists['died_dt'] = (born_datetime, died_datetime) print(scientists.shape) print(scientists.head()) random.seed(42) random.shuffle(scientists['Age']) # 此修改会作用于scientists print(scientists.head()) scientists['age_days_dt'] = (scientists['died_dt'] - scientists['born_dt']) print(scientists.head()) 执行结果: $ python3 change.py object object Name Born Died Age Occupation 0 Rosaline Franklin 1920-07-25 1958-04-16 37 Chemist 1 William Gosset 1876-06-13 1937-10-16 61 Statistician 2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse 3 Marie Curie 1867-11-07 1934-07-04 66 Chemist 4 Rachel Carson 1907-05-27 1964-04-14 56 Biologist (8, 7) Name Born Died Age Occupation born_dt \ 0 Rosaline Franklin 1920-07-25 1958-04-16 37 Chemist 1920-07-25 1 William Gosset 1876-06-13 1937-10-16 61 Statistician 1876-06-13 2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse 1820-05-12 3 Marie Curie 1867-11-07 1934-07-04 66 Chemist 1867-11-07 4 Rachel Carson 1907-05-27 1964-04-14 56 Biologist 1907-05-27 died_dt 0 1958-04-16 1 1937-10-16 2 1910-08-13 3 1934-07-04 4 1964-04-14 /usr/lib/python3.5/random.py:272: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy x[i], x[j] = x[j], x[i] Name Born Died Age Occupation born_dt \ 0 Rosaline Franklin 1920-07-25 1958-04-16 66 Chemist 1920-07-25 1 William Gosset 1876-06-13 1937-10-16 56 Statistician 1876-06-13 2 Florence Nightingale 1820-05-12 1910-08-13 41 Nurse 1820-05-12 3 Marie Curie 1867-11-07 1934-07-04 77 Chemist 1867-11-07 4 Rachel Carson 1907-05-27 1964-04-14 90 Biologist 1907-05-27 died_dt 0 1958-04-16 1 1937-10-16 2 1910-08-13 3 1934-07-04 4 1964-04-14 Name Born Died Age Occupation born_dt \ 0 Rosaline Franklin 1920-07-25 1958-04-16 66 Chemist 1920-07-25 1 William Gosset 1876-06-13 1937-10-16 56 Statistician 1876-06-13 2 Florence Nightingale 1820-05-12 1910-08-13 41 Nurse 1820-05-12 3 Marie Curie 1867-11-07 1934-07-04 77 Chemist 1867-11-07 4 Rachel Carson 1907-05-27 1964-04-14 90 Biologist 1907-05-27 died_dt age_days_dt 0 1958-04-16 13779 days 1 1937-10-16 22404 days 2 1910-08-13 32964 days 3 1934-07-04 24345 days 4 1964-04-14 20777 days 数据导入导出 out.py #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: china-testing#126.com wechat:pythontesting qq群:630011153 # CreateDate: 2018-3-31 # out.py import pandas as pd import numpy as np import random scientists = pd.read_csv('../data/scientists.csv') names = scientists['Name'] print(names) names.to_pickle('../output/scientists_names_series.pickle') scientists.to_pickle('../output/scientists_df.pickle') # .p, .pkl, .pickle 是常用的pickle文件扩展名 scientist_names_from_pickle = pd.read_pickle('../output/scientists_df.pickle') print(scientist_names_from_pickle) names.to_csv('../output/scientist_names_series.csv') scientists.to_csv('../output/scientists_df.tsv', sep='\t') # 不输出行号 scientists.to_csv('../output/scientists_df_no_index.csv', index=None) # Series可以转为df再输出成excel文件 names_df = names.to_frame() names_df.to_excel('../output/scientists_names_series_df.xls') names_df.to_excel('../output/scientists_names_series_df.xlsx') scientists.to_excel('../output/scientists_df.xlsx', sheet_name='scientists', index=False) 执行结果: $ python3 out.py 0 Rosaline Franklin 1 William Gosset 2 Florence Nightingale 3 Marie Curie 4 Rachel Carson 5 John Snow 6 Alan Turing 7 Johann Gauss Name: Name, dtype: object Name Born Died Age Occupation 0 Rosaline Franklin 1920-07-25 1958-04-16 37 Chemist 1 William Gosset 1876-06-13 1937-10-16 61 Statistician 2 Florence Nightingale 1820-05-12 1910-08-13 90 Nurse 3 Marie Curie 1867-11-07 1934-07-04 66 Chemist 4 Rachel Carson 1907-05-27 1964-04-14 56 Biologist 5 John Snow 1813-03-15 1858-06-16 45 Physician 6 Alan Turing 1912-06-23 1954-06-07 41 Computer Scientist 7 Johann Gauss 1777-04-30 1855-02-23 77 Mathematician 注意:序列一般是直接输出成excel文件 更多的输入输出方法: 方式 描述 to_clipboard 将数据保存到系统剪贴板进行粘贴 to_dense 将数据转换为常规“密集”DataFrame to_dict 将数据转换为Python字典 to_gbq 将数据转换为Google BigQuery表格 toJidf 将数据保存为分层数据格式(HDF) to_msgpack 将数据保存到可移植的类似JSON的二进制文件中 toJitml 将数据转换为HTML表格 tojson 将数据转换为JSON字符串 toJatex 将数据转换为LTEXtabular环境 to_records 将数据转换为记录数组 to_string 将DataFrame显示为stdout的字符串 to_sparse 将数据转换为SparceDataFrame to_sql 将数据保存到SQL数据库中 to_stata 将数据转换为Stata dta文件 读CSV文件 read_csv.py #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: china-testing#126.com wechat:pythontesting QQ群:630011153 # CreateDate: 2018-3-9 # read_csv.py import pandas as pd df = pd.read_csv("1.csv", header=None) # 不读取列名 print("df:") print(df) print("df.head():") print(df.head()) # head(self, n=5),默认为5行,类似的有tail print("df.tail():") print(df.tail()) df = pd.read_csv("1.csv") # 默认读取列名 print("df:") print(df) df = pd.read_csv("1.csv", names=['号码','群号']) # 自定义列名 print("df:") print(df) # 自定义列名,去掉第一行 df = pd.read_csv("1.csv", skiprows=[0], names=['号码','群号']) print("df:") print(df) 执行结果: df: 0 1 0 qq qqgroup 1 37391319 144081101 2 37391320 144081102 3 37391321 144081103 4 37391322 144081104 5 37391323 144081105 6 37391324 144081106 7 37391325 144081107 8 37391326 144081108 9 37391327 144081109 10 37391328 144081110 11 37391329 144081111 12 37391330 144081112 13 37391331 144081113 14 37391332 144081114 15 37391333 144081115 df.head(): 0 1 0 qq qqgroup 1 37391319 144081101 2 37391320 144081102 3 37391321 144081103 4 37391322 144081104 df.tail(): 0 1 11 37391329 144081111 12 37391330 144081112 13 37391331 144081113 14 37391332 144081114 15 37391333 144081115 df: qq qqgroup 0 37391319 144081101 1 37391320 144081102 2 37391321 144081103 3 37391322 144081104 4 37391323 144081105 5 37391324 144081106 6 37391325 144081107 7 37391326 144081108 8 37391327 144081109 9 37391328 144081110 10 37391329 144081111 11 37391330 144081112 12 37391331 144081113 13 37391332 144081114 14 37391333 144081115 df: 号码 群号 0 qq qqgroup 1 37391319 144081101 2 37391320 144081102 3 37391321 144081103 4 37391322 144081104 5 37391323 144081105 6 37391324 144081106 7 37391325 144081107 8 37391326 144081108 9 37391327 144081109 10 37391328 144081110 11 37391329 144081111 12 37391330 144081112 13 37391331 144081113 14 37391332 144081114 15 37391333 144081115 df: 号码 群号 0 37391319 144081101 1 37391320 144081102 2 37391321 144081103 3 37391322 144081104 4 37391323 144081105 5 37391324 144081106 6 37391325 144081107 7 37391326 144081108 8 37391327 144081109 9 37391328 144081110 10 37391329 144081111 11 37391330 144081112 12 37391331 144081113 13 37391332 144081114 14 37391333 144081115 写CSV文件 #!/usr/bin/python3 # -*- coding: utf-8 -*- # write_csv.py import pandas as pd data ={'qq': [37391319,37391320], 'group':[1,2]} df = pd.DataFrame(data=data, columns=['qq','group']) df.to_csv('2.csv',index=False) 读写excel和csv类似,不过要改用read_excel来读,excel_summary_demo, 提供了多个excel求和的功能,可以做为excel读写的实例,这里不再赘述。 参考资料 技术支持qq群144081101 591302926 567351477 钉钉免费群21745728 本文最新版本地址 本文涉及的python测试开发库 谢谢点赞! 本文相关海量书籍下载 源码下载 本文英文版书籍下载

优秀的个人博客,低调大师

Android笔记:bitmap转换与处理相关工具类,Bitmap与DrawAble与byte[]与InputStream之间的转换

1.将view转为bitmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // 将view转为bitmap public static Bitmap getBitmapFromView(View view) { // Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); // Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); // Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null ) // has background drawable, then draw it on the canvas bgDrawable.draw(canvas); else // does not have background drawable, then draw white background on // the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); // return the bitmap return returnedBitmap; } 2.将view转为bitmap 1 2 3 4 5 6 7 8 // 将view转为bitmap public static Bitmap viewToBitmap(View view) { view.setDrawingCacheEnabled( true ); view.buildDrawingCache(); Bitmap bm = view.getDrawingCache(); return bm; } 3.将xml转为bitmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // 将xml转为bitmap public static Bitmap convertBitmapFromXML(Context context, String clusterSize, Bitmap bm) { View layout = LayoutInflater.from(context).inflate(R.layout.estatecartlist_item, null ); View bitmapView = layout.findViewById(R.id.estatecartlist_item_bitmap); TextView xml_text = (TextView) layout.findViewById(R.id.item_estatecart_tv_name); ImageView image = (ImageView) layout.findViewById(R.id.item_estatecart_iv_main); image.setImageBitmap(bm); xml_text.setText(clusterSize); bitmapView.measure(MeasureSpec.makeMeasureSpec( 0 , MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec( 0 , MeasureSpec.UNSPECIFIED)); bitmapView.layout( 0 , 0 , bitmapView.getMeasuredWidth(), bitmapView.getMeasuredHeight()); final Bitmap clusterBitmap = Bitmap.createBitmap(bitmapView.getMeasuredWidth(), bitmapView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(clusterBitmap); bitmapView.draw(canvas); return clusterBitmap; } ==============参考资料=================== * 1.http://stackoverflow.com/questions/7200535/how-to-convert-views-to-bitmap * 2.http://stackoverflow.com/questions/5536066/convert-view-to-bitmap-on-android/9595919#9595919 * 3.http://stackoverflow.com/questions/12402392/android-converting-xml-view-to-bitmap-without-showing-it 4.图片缩放与压缩 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 // 按大小缩放 private Bitmap getimage(String srcPath) { BitmapFactory.Options newOpts = new BitmapFactory.Options(); // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 newOpts.inJustDecodeBounds = true ; Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts); // 此时返回bm为空 newOpts.inJustDecodeBounds = false ; int w = newOpts.outWidth; int h = newOpts.outHeight; // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 float hh = 800f; // 这里设置高度为800f float ww = 480f; // 这里设置宽度为480f // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 int be = 1 ; // be=1表示不缩放 if (w > h && w > ww) { // 如果宽度大的话根据宽度固定大小缩放 be = ( int ) (newOpts.outWidth / ww); } else if (w < h && h > hh) { // 如果高度高的话根据宽度固定大小缩放 be = ( int ) (newOpts.outHeight / hh); } if (be <= 0 ) be = 1 ; newOpts.inSampleSize = be; // 设置缩放比例 // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 bitmap = BitmapFactory.decodeFile(srcPath, newOpts); return compressImage(bitmap); // 压缩好比例大小后再进行质量压缩 } // 图片质量压缩 private static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 100 , baos); // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 int options = 100 ; while (baos.toByteArray().length / 1024 > 100 ) { // 循环判断如果压缩后图片是否大于100kb,大于继续压缩 baos.reset(); // 重置baos即清空baos image.compress(Bitmap.CompressFormat.JPEG, options, baos); // 这里压缩options%,把压缩后的数据存放到baos中 options -= 10 ; // 每次都减少10 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); // 把压缩后的数据baos存放到ByteArrayInputStream中 Bitmap bitmap = BitmapFactory.decodeStream(isBm, null , null ); // 把ByteArrayInputStream数据生成图片 return bitmap; } // 图片按比例大小压缩 private static Bitmap comp(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 100 , baos); if (baos.toByteArray().length / 1024 > 1024 ) { // 判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出 baos.reset(); // 重置baos即清空baos image.compress(Bitmap.CompressFormat.JPEG, 50 , baos); // 这里压缩50%,把压缩后的数据存放到baos中 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); BitmapFactory.Options newOpts = new BitmapFactory.Options(); // 开始读入图片,此时把options.inJustDecodeBounds 设回true了 newOpts.inJustDecodeBounds = true ; Bitmap bitmap = BitmapFactory.decodeStream(isBm, null , newOpts); newOpts.inJustDecodeBounds = false ; int w = newOpts.outWidth; int h = newOpts.outHeight; // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 float hh = 800f; // 这里设置高度为800f float ww = 480f; // 这里设置宽度为480f // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 int be = 1 ; // be=1表示不缩放 if (w > h && w > ww) { // 如果宽度大的话根据宽度固定大小缩放 be = ( int ) (newOpts.outWidth / ww); } else if (w < h && h > hh) { // 如果高度高的话根据宽度固定大小缩放 be = ( int ) (newOpts.outHeight / hh); } if (be <= 0 ) be = 1 ; newOpts.inSampleSize = be; // 设置缩放比例 // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 isBm = new ByteArrayInputStream(baos.toByteArray()); bitmap = BitmapFactory.decodeStream(isBm, null , newOpts); return compressImage(bitmap); // 压缩好比例大小后再进行质量压缩 } 5.图片转为文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // 图片转为文件 public static boolean saveBitmap2file(Bitmap bmp, String filename) { CompressFormat format = Bitmap.CompressFormat.JPEG; int quality = 100 ; OutputStream stream = null ; try { stream = new FileOutputStream( "/sdcard/" + filename); } catch (FileNotFoundException e) { e.printStackTrace(); } return bmp.compress(format, quality, stream); } 6.屏幕截屏方法 1 2 3 4 5 6 7 8 9 // 屏幕截屏方法 获取当前屏幕bitmap,转换成bytes[] 调用 UI分享方法 public void printscreen_share(View v) { View view1 = getWindow().getDecorView(); Display display = getWindowManager().getDefaultDisplay(); view1.layout( 0 , 0 , display.getWidth(), display.getHeight()); view1.setDrawingCacheEnabled( true ); Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache()); } 7.把Bitmap 转成 Byte 1 2 3 4 5 6 7 // 把Bitmap 转成 Byte public static byte [] Bitmap2Bytes(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100 , baos); return baos.toByteArray(); } 8.图片转为文件 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 // 图片转为文件 public static boolean saveBitmap2file(Bitmap bmp) { CompressFormat format = Bitmap.CompressFormat.PNG; int quality = 100 ; OutputStream stream = null ; try { // 判断SDcard状态 if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // 错误提示 return false ; } // 检查SDcard空间 File SDCardRoot = Environment.getExternalStorageDirectory(); if (SDCardRoot.getFreeSpace() < 10000 ) { // 弹出对话框提示用户空间不够 Log.e( "Utils" , "存储空间不够" ); return false ; } // 在SDcard创建文件夹及文件 File bitmapFile = new File(SDCardRoot.getPath() + FILE_PATH); bitmapFile.getParentFile().mkdirs(); // 创建文件夹 stream = new FileOutputStream(SDCardRoot.getPath() + FILE_PATH); // "/sdcard/" } catch (FileNotFoundException e) { e.printStackTrace(); } return bmp.compress(format, quality, stream); } 9.下载图片 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 // 下载图片 public static Bitmap loadImage(String... params) { InputStream is = null ; Bitmap bitmap = null ; try { URL url = new URL(params[ 0 ]); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout( 5000 ); conn.setConnectTimeout( 5000 ); if (HttpURLConnection.HTTP_OK != conn.getResponseCode()) { // 网络连接异常 Log.e( "" , "loadImage连接异常" ); return null ; } is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if ( null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return bitmap; } 10.byte[]转换成Bitmap 1 2 3 4 5 6 7 8 9 // byte[]转换成Bitmap public static Bitmap Bytes2Bitmap( byte [] b) { if (b.length != 0 ) { return BitmapFactory.decodeByteArray(b, 0 , b.length); } return null ; } 11.将字符串转换成Bitmap类型 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public static Bitmap stringtoBitmap(String string) { // 将字符串转换成Bitmap类型 Bitmap bitmap = null ; try { byte [] bitmapArray; bitmapArray = Base64.decode(string, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0 , bitmapArray.length); } catch (Exception e) { e.printStackTrace(); } return bitmap; } 12.将Bitmap转换成字符串 1 2 3 4 5 6 7 8 9 10 public static String bitmaptoString(Bitmap bitmap) { // 将Bitmap转换成字符串 String string = null ; ByteArrayOutputStream bStream = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.PNG, 100 , bStream); byte [] bytes = bStream.toByteArray(); string = Base64.encodeToString(bytes, Base64.DEFAULT); return string; } 13.byte[]转为文件 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 //byte[]转为文件 public static File getFileFromBytes( byte [] b) { BufferedOutputStream stream = null ; File file = null ; try { // 判断SDcard状态 if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // 错误提示 return null ; } // 检查SDcard空间 File SDCardRoot = Environment.getExternalStorageDirectory(); if (SDCardRoot.getFreeSpace() < 10000 ) { // 弹出对话框提示用户空间不够 Log.e( "Utils" , "存储空间不够" ); return null ; } // 在SDcard创建文件夹及文件 File bitmapFile = new File(SDCardRoot.getPath() + FILE_PATH); bitmapFile.getParentFile().mkdirs(); // 创建文件夹 FileOutputStream fstream = new FileOutputStream(bitmapFile); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null ) { try { stream.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return file; } 14.图片压缩 1 2 3 4 5 6 7 8 9 10 11 12 13 //图片缩放 public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) { final float densityMultiplier = context.getResources().getDisplayMetrics().density; int h = ( int ) (newHeight * densityMultiplier); int w = ( int ) (h * photo.getWidth() / (( double ) photo.getHeight())); photo = Bitmap.createScaledBitmap(photo, w, h, true ); return photo; } 15.将byte[]转换成InputStream 1 2 3 4 5 6 // 将byte[]转换成InputStream public InputStream Byte2InputStream( byte [] b) { ByteArrayInputStream bais = new ByteArrayInputStream(b); return bais; } 16.将InputStream转换成byte[] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // 将InputStream转换成byte[] public byte [] InputStream2Bytes(InputStream is) { String str = "" ; byte [] readByte = new byte [ 1024 ]; int readCount = - 1 ; try { while ((readCount = is.read(readByte, 0 , 1024 )) != - 1 ) { str += new String(readByte).trim(); } return str.getBytes(); } catch (Exception e) { e.printStackTrace(); } return null ; } 17.将Bitmap转换成InputStream 1 2 3 4 5 6 7 8 // 将Bitmap转换成InputStream public InputStream Bitmap2InputStream(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.JPEG, 100 , baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is; } 18.将Bitmap转换成InputStream 1 2 3 4 5 6 7 8 // 将Bitmap转换成InputStream public InputStream Bitmap2InputStream(Bitmap bm, int quality) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, quality, baos); InputStream is = new ByteArrayInputStream(baos.toByteArray()); return is; } 19.将InputStream转换成Bitmap 1 2 3 4 5 // 将InputStream转换成Bitmap public Bitmap InputStream2Bitmap(InputStream is) { return BitmapFactory.decodeStream(is); } 20.Drawable转换成InputStream 1 2 3 4 5 6 // Drawable转换成InputStream public InputStream Drawable2InputStream(Drawable d) { Bitmap bitmap = this .drawable2Bitmap(d); return this .Bitmap2InputStream(bitmap); } 21.InputStream转换成Drawable 1 2 3 4 5 6 // InputStream转换成Drawable public Drawable InputStream2Drawable(InputStream is) { Bitmap bitmap = this .InputStream2Bitmap(is); return this .bitmap2Drawable(bitmap); } 22.Drawable转换成byte[] 1 2 3 4 5 6 // Drawable转换成byte[] public byte [] Drawable2Bytes(Drawable d) { Bitmap bitmap = this .drawable2Bitmap(d); return this .Bitmap2Bytes(bitmap); } 23.byte[]转换成Drawable 1 2 3 4 5 6 // byte[]转换成Drawable public Drawable Bytes2Drawable( byte [] b) { Bitmap bitmap = this .Bytes2Bitmap(b); return this .bitmap2Drawable(bitmap); } 24.Drawable转换成Bitmap 1 2 3 4 5 6 7 8 9 10 // Drawable转换成Bitmap public Bitmap drawable2Bitmap(Drawable drawable) { Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds( 0 , 0 , drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; } 25.Bitmap转换成Drawable 1 2 3 4 5 6 7 // Bitmap转换成Drawable public Drawable bitmap2Drawable(Bitmap bitmap) { BitmapDrawable bd = new BitmapDrawable(bitmap); Drawable d = (Drawable) bd; return d; } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1304090,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册