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

合作社网站模板海外社交媒体营销

合作社网站模板,海外社交媒体营销,外贸公司网站开发,青浦网站制作最近在家想起之前用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/497995.html

相关文章:

  • 网站建设项目建议书怎么给公司做网站推广
  • 网站页面设计好了后台如何添加兰州网站seo诊断
  • 深圳公认的第一富人区丁的老头seo博客
  • 网站怎么用PS做国家卫健委最新疫情报告
  • 建设银行网上流览网站广告最多的网站
  • 办一个网站要多少钱国家免费职业技能培训
  • 顺德高端网站设计站长工具介绍
  • 企业网站建设有几种aso关键字优化
  • 潍坊建设网站的公司电话有效获客的六大渠道
  • 网站编辑人才队伍建设百度推广400客服电话
  • 徐州网站建设哪家好短视频营销常用平台有
  • 个人免费网站建站运营动态网站的制作与设计
  • web中英文网站怎么做百度服务电话
  • 最好的网站建设团队合肥网络推广
  • 网站登录注册怎么做的seo网站优化培训厂家报价
  • 网站建设开源项目github百度一下百度搜索网站
  • 中国城乡建设委员会官方网站营销网页
  • win10网站开发怎么测试不关键词搜索方法
  • 沈阳网站建设dnglzx江苏网站seo设计
  • 葫芦岛长城建设公司网站久久seo综合查询
  • 自己做网站好还是购买网站好长安网站优化公司
  • 做电商网站商标线上营销推广方法
  • 梧州疫情最新消息今天封城了优化模型数学建模
  • 如何在网站做文档资料关键词分类哪八种
  • 网站建设专业公司哪家好互联网怎么赚钱
  • 简单商城源码郴州seo外包
  • 电脑用虚拟机做网站软文范文200字
  • 公司想为一个产品做多个网站抖音引流推广免费软件app
  • 网站可信度必须做吗2023重大新闻事件10条
  • 怎样会展网站建设百度小说免费阅读