PyQt5 直接调用网络图片插入界面

# PyQt5加载网络图片
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import (QWidget,  QLabel, QVBoxLayout)
from PyQt5.QtGui import  QPixmap


class webImg:
    pass
    
    

if __name__ == '__main__':  
    app = QApplication(sys.argv) 

    import requests
     
    url='http://XXXXX/XXX.jpg' 
    req = requests.get(url)  # 发送图片请求

    code_pic = req.content   #直接存入内存
    print(type(code_pic)) # 查看返回类型<class 'bytes'>
    print(dir(req))  # dir函数传入数据类型返回该数据类型的所有内置方法

    #思考一下,是否可以直接调用本地png?

    #具体如下:

    # with open('code_pic.png',mode='wb') as f:    # 保存到硬盘
    #        f.write(code_pic)
    # with open('code_pic.png',mode='rb') as f:    # 读取到内存
    #        code_pic = f.read()
    photo = QPixmap()  #定义photo为pixmap类
    # photo.loadFromData(req.content, "JPG")
    photo.loadFromData(code_pic) # 把二进制转换成qpixmap
    
    label= QLabel()
    label.setPixmap(photo) #这里直接调用qpixmap 

    widget = QWidget()
    layout =QVBoxLayout()
    widget.setLayout(layout)
    layout.addWidget(label)
    
    widget.show()


    sys.exit(app.exec_())

PyQt5 直接调用网络图片插入界面

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 SAR 图像检测界面模板,使用 PyQt5 编写。 ``` import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel, QPushButton, QFileDialog from PyQt5.QtGui import QPixmap from PyQt5.QtCore import Qt class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("SAR 图像检测") self.setGeometry(100, 100, 800, 600) self.image_label = QLabel(self) self.image_label.setGeometry(20, 20, 600, 500) self.detect_button = QPushButton("检测", self) self.detect_button.setGeometry(650, 20, 100, 50) self.detect_button.clicked.connect(self.detect_image) self.open_button = QPushButton("打开图像", self) self.open_button.setGeometry(650, 100, 100, 50) self.open_button.clicked.connect(self.open_image) self.threshold_label = QLabel("阈值:", self) self.threshold_label.setGeometry(650, 200, 50, 30) self.threshold_input = QLineEdit(self) self.threshold_input.setGeometry(700, 200, 50, 30) def open_image(self): file_path, _ = QFileDialog.getOpenFileName(self, "打开图像", "", "Images (*.png *.xpm *.jpg *.bmp)") if file_path: pixmap = QPixmap(file_path) self.image_label.setPixmap(pixmap) def detect_image(self): threshold = int(self.threshold_input.text()) # TODO: SAR 图像检测代码 if __name__ == "__main__": app = QApplication(sys.argv) main_window = MainWindow() main_window.show() sys.exit(app.exec_()) ``` 这个模板创建了一个主窗口,包含一个用于显示图像的标签、一个用于打开图像文件的按钮、一个用于执行图像检测的按钮、以及一个用于输入阈值的文本框。 打开图像按钮使用 `QFileDialog` 对话框让用户选择图像文件,并使用 `QPixmap` 将其显示在标签中。 检测图像按钮调用 `detect_image` 方法,该方法从文本框中获取阈值,并调用 SAR 图像检测代码进行检测。 你可以根据你自己的需求修改这个模板,以实现你想要的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值