社区
脚本语言
帖子详情
[PYTHON]如何把一个图片文件以二进制显示出来???
史前文物
2006-10-22 07:15:07
1)要在屏幕上显示文件的二进制码。。。。
2)fileData = open('data.jpg','ab')
fileData.write('0001')
这样可以吗??? 如果可以,如何解决问题 1。。。。。
...全文
1470
2
打赏
收藏
[PYTHON]如何把一个图片文件以二进制显示出来???
1)要在屏幕上显示文件的二进制码。。。。 2)fileData = open('data.jpg','ab') fileData.write('0001') 这样可以吗??? 如果可以,如何解决问题 1。。。。。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
iambic
2006-10-22
打赏
举报
回复
对,是很简单。我刚才看到贴子,想找下Python有没有把二进制数据转成二进制串的函数,一时没找到。你愿意使用自己写的函数也好,但是注意性能。可以先计算所有字符的二进制避免重复计算。
bits = map(numberToBinary, range(256))
fileData = open('data.jpg','rb')
all = fileData.readlines()
for b in all:
print bits[ord(b)]
也可以尝试hash:
bits = {}
for b in range(256):
bits[chr(b)] = numberToBinary(b)
fileData = open('data.jpg','rb')
all = fileData.readlines()
for b in all:
print bits[b]
不过,不管怎么说print那么多串到屏幕肯定挺慢的。试过再说。祝楼主好运。
史前文物
2006-10-22
打赏
举报
回复
I known how to do it.
Because read() return a string. so
1) bytes = read(1) #read the file by bit.
2) chrString = ord(bytes) #convert the string to ASCII.
3) print numberToBinary(chrString) #convert the ASCII to Binary using
my function.
4) Loop
基于wx
Python
和PySerial实现的串口助手
基于wx
Python
和PySerial实现的串口助手,实现了常用的接收、发送、
二进制
显示
、
二进制
发送等功能; 使用了
Python
、wx
Python
、PySerial、线程、
图片
内嵌等多种实用GUI编程技术,且单
文件
实现,简单易懂,可以作为学习GUI编程的
一个
很好的例程,也可以作为自己实现更完整串口助手功能的起点!!!
python
二进制
显示
图片
_
python
读取
二进制
显示
图片
案例
我就废话不多说了,大家还是直接看代码吧!import matplotlib.pyplot as pltimport numpy as npf = open("bwall.bmpx", mode="rb")x = np.fromfile(f, dtype=np.ubyte)#x = x[0:1920]x = x[1920:3840]#x = x[3840:5760]x = x.reshape(60,...
python
打开
图片
的
二进制
文件
_
python
读取
二进制
显示
图片
案例
我就废话不多说了,大家还是直接看代码吧!import matplotlib.pyplot as pltimport numpy as npf = open('bwall.bmpx', mode='rb')x = np.fromfile(f, dtype=np.ubyte)#x = x[0:1920]x = x[1920:3840]#x = x[3840:5760]x = x.reshape(60,...
Python
操作
二进制
文件
在计算机中,
文件
可以分为两种类型:文本
文件
和
二进制
文件
。文本
文件
包含人类可读的字符,而
二进制
文件
包含计算机指令或数据,无法直接阅读。常见的
二进制
文件
包括
图片
、音频、视频、可执行
文件
等。
Python
提供了处理
二进制
文件
的工具,允许你读写任意类型的数据。
python
如何读取
二进制
文件
为
图片
_
python
读取
二进制
显示
图片
案例
我就废话不多说了,大家还是直接看代码吧!import matplotlib.pyplot as pltimport numpy as npf = open('bwall.bmpx', mode='rb')x = np.fromfile(f, dtype=np.ubyte)#x = x[0:1920]x = x[1920:3840]#x = x[3840:5760]x = x.reshape(60,...
脚本语言
37,743
社区成员
34,213
社区内容
发帖
与我相关
我的任务
脚本语言
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
复制链接
扫一扫
分享
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
试试用AI创作助手写篇文章吧
+ 用AI写文章