当前位置: 首页 > wzjs >正文

著名的外贸网站2013电子商务网站建设

著名的外贸网站,2013电子商务网站建设,深圳的互联网公司,快速开发平台有哪些最近在家想起之前用Java写的小游戏,弄完发现之前有Python代码,该死,不过新的这个代码也完善了一下。 滑块拼图小游戏(Java)_滑动拼图游戏开发-CSDN博客https://blog.csdn.net/weixin_64066303/article/details/130415…

最近在家想起之前用Java写的小游戏,弄完发现之前有Python代码,该死,不过新的这个代码也完善了一下。

滑块拼图小游戏(Java)_滑动拼图游戏开发-CSDN博客https://blog.csdn.net/weixin_64066303/article/details/130415994?ops_request_misc=%257B%2522request%255Fid%2522%253A%252238bcc7987422409c36f17617ad46a354%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=38bcc7987422409c36f17617ad46a354&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-130415994-null-null.nonecase&utm_term=%E6%8B%BC%E5%9B%BE&spm=1018.2226.3001.4450 先自己选择输入的图片,默认是输出到项目文件夹中,可以自己选择其他的文件夹,选择需要拆分的行数和列数,可以通过deepseek来输出文件名的格式。

import sys
import os
import shutil
from PIL import Image
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QLabel, QPushButton,QVBoxLayout, QHBoxLayout, QFileDialog, QSpinBox, QGroupBox,QMessageBox)
from PyQt5.QtCore import Qtclass ImageSplitterApp(QMainWindow):def __init__(self):super().__init__()self.setWindowTitle("图片拆分工具")self.setFixedSize(450, 400)  # 稍微增大窗口以适应更多内容# 获取项目目录作为默认输出路径self.project_dir = os.path.dirname(os.path.abspath(__file__))self.default_output_dir = os.path.join(self.project_dir, "split_results")self.output_dir = self.default_output_dirself.image_path = Noneself.original_filename = Noneself.init_ui()self.center_window()def center_window(self):"""将窗口居中显示在屏幕上"""screen = QApplication.primaryScreen().geometry()size = self.geometry()self.move((screen.width() - size.width()) // 2,(screen.height() - size.height()) // 2)def init_ui(self):# 主部件和布局main_widget = QWidget()main_layout = QVBoxLayout()main_layout.setAlignment(Qt.AlignTop)# 图片选择区域img_group = QGroupBox("图片选择")img_layout = QVBoxLayout()self.img_label = QLabel("未选择图片")self.img_label.setWordWrap(True)img_btn = QPushButton("选择图片")img_btn.clicked.connect(self.select_image)img_layout.addWidget(self.img_label)img_layout.addWidget(img_btn)img_group.setLayout(img_layout)# 拆分设置区域split_group = QGroupBox("拆分设置")split_layout = QHBoxLayout()row_layout = QVBoxLayout()row_label = QLabel("行数:")self.row_spin = QSpinBox()self.row_spin.setRange(1, 50)self.row_spin.setValue(2)row_layout.addWidget(row_label)row_layout.addWidget(self.row_spin)col_layout = QVBoxLayout()col_label = QLabel("列数:")self.col_spin = QSpinBox()self.col_spin.setRange(1, 50)self.col_spin.setValue(2)col_layout.addWidget(col_label)col_layout.addWidget(self.col_spin)split_layout.addLayout(row_layout)split_layout.addLayout(col_layout)split_group.setLayout(split_layout)# 输出信息区域output_group = QGroupBox("输出设置")output_layout = QVBoxLayout()self.output_label = QLabel(f"输出文件夹: {self.output_dir}")self.output_label.setWordWrap(True)output_btn = QPushButton("更改输出文件夹")output_btn.clicked.connect(self.select_output_dir)output_layout.addWidget(self.output_label)output_layout.addWidget(output_btn)output_group.setLayout(output_layout)# 操作按钮self.split_btn = QPushButton("拆分图片")self.split_btn.setEnabled(False)self.split_btn.clicked.connect(self.split_image)self.split_btn.setMinimumHeight(40)  # 增大按钮高度# 添加到主布局main_layout.addWidget(img_group)main_layout.addWidget(split_group)main_layout.addWidget(output_group)main_layout.addWidget(self.split_btn)main_widget.setLayout(main_layout)self.setCentralWidget(main_widget)def select_image(self):file_path, _ = QFileDialog.getOpenFileName(self, "选择图片", "","图片文件 (*.png *.jpg *.jpeg *.bmp *.gif)")if file_path:self.image_path = file_pathself.original_filename = os.path.basename(file_path)display_text = f"已选择: {self.original_filename}"if len(display_text) > 40:display_text = f"已选择: ...{self.original_filename[-30:]}"self.img_label.setText(display_text)self.split_btn.setEnabled(True)def select_output_dir(self):dir_path = QFileDialog.getExistingDirectory(self, "选择输出文件夹",self.project_dir  # 从项目目录开始)if dir_path:self.output_dir = dir_pathdisplay_text = f"输出文件夹: {dir_path}"if len(display_text) > 60:display_text = f"输出文件夹: ...{dir_path[-50:]}"self.output_label.setText(display_text)def split_image(self):if not self.image_path:QMessageBox.warning(self, "警告", "请先选择图片!")returntry:rows = self.row_spin.value()cols = self.col_spin.value()img = Image.open(self.image_path)img_width, img_height = img.size# 计算每个子图的大小tile_width = img_width // colstile_height = img_height // rows# 确保输出目录存在os.makedirs(self.output_dir, exist_ok=True)# 复制原始图片到输出目录original_output_path = os.path.join(self.output_dir, self.original_filename)shutil.copy(self.image_path, original_output_path)# 拆分图片并保存为 main_数字.pngcount = 1for i in range(rows):for j in range(cols):left = j * tile_widthupper = i * tile_heightright = left + tile_widthlower = upper + tile_height# 确保最后一块包含剩余部分if j == cols - 1:right = img_widthif i == rows - 1:lower = img_heighttile = img.crop((left, upper, right, lower))# 生成文件名:main_数字.pngoutput_path = os.path.join(self.output_dir, f"main_{count}.png")tile.save(output_path)count += 1QMessageBox.information(self, "完成",f"图片已拆分为 {rows}×{cols} = {count - 1} 个小图!\n"f"保存到: {self.output_dir}\n\n"f"包含文件:\n"f"- 原始图片: {self.original_filename}\n"f"- 拆分图片: main_1.png 到 main_{count - 1}.png")except Exception as e:QMessageBox.critical(self, "错误", f"处理图片时出错:\n{str(e)}")if __name__ == "__main__":app = QApplication(sys.argv)window = ImageSplitterApp()window.show()sys.exit(app.exec_())

http://www.dtcms.com/wzjs/823529.html

相关文章:

  • 青岛网站维护公司wordpress分享统计插件
  • 中国建设银行官方网站手机银行网站开发应该学哪门语言
  • 关键词营销推广seo优化工作
  • 网站免费站南京城乡建设局网站
  • 闵行网站建设哪家好中国古风网站模板
  • 环保设备东莞网站建设wordpress什么编辑器好用吗
  • 网站微信二维码悬浮开网上授课的网站应该怎么做
  • 电子商务网站建设 课件重庆建设厂招工信息网站
  • 网站开发需求文档模板带er图叶文语 厦门建设局
  • 电脑网站视频怎么下载合肥 企业网站设计公司
  • pt网站怎么下载与做丹江口网站建设
  • 怎么再各网站上做宣传天津建设工程信息网网上报名
  • 义乌做网站公司网站做计算功能
  • 网站设计培训班老师百度一下京东
  • 百度搜不到网站青色网站欣赏
  • 上海seo优化外包公司seo 网站地图优化
  • 网站建站免费空间如何做木工雕刻机网站
  • 如何创建私人网站怎么把广告发到各大平台
  • 餐饮公司最好的网站建设品牌推广方案100例
  • 网站建设实训 课程标准dw网页制作破解版
  • 互动网站制作哪些网站是做快消品的
  • 网站备案平台的服务简介有些网站勤换域名
  • 广西专业网站建设鹰眼智能营销系统
  • 制作企业网站的秘诀4399小游戏电脑版网页链接
  • 基层建设期刊上什么网站查询文章国家工程招标网公告
  • 宜春网站设计公司怎样上传网站到百度
  • 哪个网站能下载gif校园文化建设
  • 教育网站制作可以自己做视频网站吗
  • 快速做网站套餐小型办公室网络布线设计方案
  • 自建网站流程渠道网络公司官网