社区
脚本语言
帖子详情
[PYTHON]如何把一个图片文件以二进制显示出来???
史前文物
2006-10-22 07:15:07
1)要在屏幕上显示文件的二进制码。。。。
2)fileData = open('data.jpg','ab')
fileData.write('0001')
这样可以吗??? 如果可以,如何解决问题 1。。。。。
...全文
1429
2
打赏
收藏
[PYTHON]如何把一个图片文件以二进制显示出来???
1)要在屏幕上显示文件的二进制码。。。。 2)fileData = open('data.jpg','ab') fileData.write('0001') 这样可以吗??? 如果可以,如何解决问题 1。。。。。
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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
读取
二进制
文件
并以16进制
显示
import binascii # 读取
二进制
文本并
显示
为16进制 def readBinfile(binFile_path:str): for i in range(16): print("%02x".upper() % i, end=' ') print() with open(binFile_path, 'rb') as f: num = 0 while 1: a = f.read(1) .
脚本语言
37,743
社区成员
34,212
社区内容
发帖
与我相关
我的任务
脚本语言
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写文章