gpt4 book ai didi

将图像转换为字节数组的 Python 脚本

转载 作者:IT老高 更新时间:2023-10-28 22:11:06 30 4
gpt4 key购买 nike

我正在编写一个 Python 脚本,我想在其中进行批量照片上传。我想读取图像并将其转换为字节数组。任何建议将不胜感激。

#!/usr/bin/python
import xmlrpclib
import SOAPpy, getpass, datetime
import urllib, cStringIO
from PIL import Image
from urllib import urlopen
import os
import io
from array import array
""" create a proxy object with methods that can be used to invoke
corresponding RPC calls on the remote server """
soapy = SOAPpy.WSDL.Proxy('localhost:8090/rpc/soap-axis/confluenceservice-v2?wsdl')
auth = soapy.login('admin', 'Cs$corp@123')

最佳答案

使用字节数组:

with open("img.png", "rb") as image:
f = image.read()
b = bytearray(f)
print b[0]

你也可以看看struct它可以进行许多此类转换。

关于将图像转换为字节数组的 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22351254/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com