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

xxx网站建设策划书范文宁波企业seo服务

xxx网站建设策划书范文,宁波企业seo服务,河南网站设计,自己做卖东西网站之前我有一篇帖子《kfb格式文件转jpg格式》讲述到 kfb > tif > jpg,但是针对于超大tif中的大图是无法顺利提取的,就算是能顺利提取,试想一下,2G的tif文件,如果能提取处理最大的那张图,并且在不压缩的…

        之前我有一篇帖子《kfb格式文件转jpg格式》讲述到 kfb ===> tif ===> jpg,但是针对于超大tif中的大图是无法顺利提取的,就算是能顺利提取,试想一下,2G的tif文件,如果能提取处理最大的那张图,并且在不压缩的情况下,jpg大图大小高达1G,前端也是无法顺利加载展示的。

        这里我为大家带来了解决方案:将tif中最大的那张图切割成 x * y 份,之后让前端去对每一份进行渲染加载。经过了两周时间,百度或是谷歌的雷都被我踩完了(搜索结果都不怎么靠谱)。多次实验后,总算是成功了。

        针对与tif中的最大的那张图的切割,我总结出了切割实现方法,仅供参考。

利用jai-imageio进行处理

package com.lonzh.utils;import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.FileImageInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;/*** 图片切割** @author DaiHaijiao*/
public class ImgCutUtil {public static void main(String[] args) throws Exception {cut("D:\\病理切片\\教学切片(新)\\BL-01-11 心肌梗死.tif");}/*** @param imageWidth         图片宽度* @param imageHeight        图片高度* @param bisectionNumWidth  宽度方向等分数* @param bisectionNumHeight 高度方向等分数*/private static List<ImgCutUtil.Position> listPosition(int imageWidth, int imageHeight, int bisectionNumWidth, int bisectionNumHeight) {List<ImgCutUtil.Position> list = new ArrayList<>();//每个部分的宽度int partWidth = imageWidth / bisectionNumWidth;//宽方向的余数int remainderWidth = imageWidth % bisectionNumWidth;//每个部分的高度int partHeight = imageHeight / bisectionNumHeight;//高方向的余数int remainderHeight = imageHeight % bisectionNumHeight;for (int i = 0; i < bisectionNumWidth; i++) {for (int j = 0; j < bisectionNumHeight; j++) {//左下角 x 坐标int left = i * partWidth;//左下角 y 坐标int bottom = j * partHeight;//右上角 x 坐标int right = i == bisectionNumWidth - 1 ? (i + 1) * partWidth + remainderWidth : (i + 1) * partWidth;//右上角 y 坐标int top = j == bisectionNumWidth - 1 ? (j + 1) * partHeight + remainderHeight : (j + 1) * partHeight;
//                System.out.println("第 " + (i * bisectionNumWidth + j + 1) + " 等分:");
//                System.out.println("左下角坐标:(" + left + ", " + bottom + ")");
//                System.out.println("右上角坐标:(" + right + ", " + top + ")");list.add(new ImgCutUtil.Position(left, bottom, right, top));}}return list;}public static List<File> cut(String tifPath) {List<File> jpgFileList = new ArrayList<>();File tifFile = new File(tifPath);String outPutDirPath = tifPath.substring(0, tifPath.lastIndexOf(".")) + "_large_img" + File.separator;File outDirPath = new File(outPutDirPath);if (!outDirPath.exists()) {outDirPath.mkdir();}try (FileImageInputStream fis = new FileImageInputStream(tifFile)) {Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("TIFF");if (!readers.hasNext()) {throw new IIOException("No suitable image reader found!");}ImageReader reader = readers.next();reader.setInput(fis, true);int w = reader.getWidth(0);int h = reader.getHeight(0);int bisectionNumWidth = 5, bisectionNumHeight = 5;List<Position> positions = listPosition(w, h, bisectionNumWidth, bisectionNumHeight);for (int i = 0; i < positions.size(); i++) {ImageReadParam imageReadParam = new ImageReadParam();Position position = positions.get(i);System.out.println(position.left + "---" + position.bottom + "---" + (position.right - position.left) + "---" + (position.top - position.bottom));imageReadParam.setSourceRegion(new Rectangle(position.left, position.bottom, position.right - position.left, position.top - position.bottom));BufferedImage image = reader.read(0, imageReadParam);File file = new File(outPutDirPath + i + ".jpg");ImageIO.write(image, "jpg", ImageIO.createImageOutputStream(file));jpgFileList.add(file);}} catch (IOException e) {e.printStackTrace();}return jpgFileList;}static class Position {//左下角 x 坐标private Integer left;//左下角 y 坐标private Integer bottom;//右上角 x 坐标private Integer right;//右上角 y 坐标private Integer top;public Position(Integer left, Integer bottom, Integer right, Integer top) {this.left = left;this.bottom = bottom;this.right = right;this.top = top;}@Overridepublic String toString() {return "Position{" +"left=" + left +", bottom=" + bottom +", right=" + right +", top=" + top +'}';}}}

上述代码说明:

1. 代码运行需要引用maven依赖

        <dependency><groupId>javax.media.jai</groupId><artifactId>jai-imageio-core</artifactId><version>1.4.0</version></dependency>

有C币的朋友可直接移步jar文件下载传送门(jar引入方式见:我的另一篇文章《本地Maven仓库导入外部jar》)

2. main方法中的测试文件较大,高达1.64G

3. 切割比较吃内存,电脑配置太低时谨慎运行,避免电脑卡死

4. 代码中我是将该tif切割成了 5 * 5 份,切割完后会在该tif文件所在文件内产生一个新的文件夹(里面就是所有切割后的小图)

裁剪后的图片图号如下:

图序如下:

不管是几乘几的切割,图序排列规则都是一样的模式,如下图规则:

如果你对图序感兴趣,或是我的这种图序觉得前端不好使用,你可以再次研究修改listPositioin方法以达到你所需的图序。

5. 计算每一份的点坐标位置时注意:tif的宽和高未必能被要切割成的宽份数和高的份数整除,所以注意余数问题。我的那个listPosition方法中已经对于余数进行了处理,详见那块代码。

6. 代码执行超大tif文件裁剪会报错,报错地方如图:

        报错原因就是tif的宽*高的值大于了Integer的最大值。解决办法很简单,报错的这个class文件位于rt.jar下面的javax.imgio下的ImageReader.class,而解决办法就在此。
        我们在我们的项目中按照这个包路径创建一个包,并在该包下创建这个类,类里面的内容直接将ImageReader.class的内容拷贝过来,之后修改报错的地方:

修改完后重新编译项目,就会在target下面生产一个ImageReader.class文件。我们只需要替换jar包中的这个class即可。

替换前先关闭idea,找到项目所用到的rt.jar

如果打不开,自己下载个7z就能打开了,之后把我们编译后的那个class拖进去即可完成替换

最后重新打开idea运行代码即可

       

        

http://www.hkea.cn/news/202197/

相关文章:

  • 康保县城乡建设委员会网站营销型网站重要特点是
  • 手机做网站的步骤跨境电商有哪些平台
  • 请人做网站要多少网络事件营销
  • 网站页脚有什么作用厦门seo哪家强
  • 东莞百度提升优化优化推广网站推荐
  • 查企业网站有哪些站长统计app软件
  • 做a高清视频在线观看网站济源新站seo关键词排名推广
  • 刚做的网站怎么搜索不出来百度seo收录软件
  • 视频拍摄app站长工具seo综合查询广告
  • 新闻单位建设网站的意义武汉seo推广优化
  • 低价网站公司软文怎么写
  • 东莞市建设公共交易中心网站百度官网首页
  • 如何建立的网站能争钱优化营商环境 助推高质量发展
  • 做百度网站营销型网站建设排名
  • 网站域名被黑国际新闻最新消息战争
  • 苏州网站开发公司济南兴田德润厉害吗网络自动推广软件
  • 广药网站建设试卷株洲最新今日头条
  • 网站建设管理考核办法微信推广平台怎么做
  • 网站新闻模块代码网络推广有哪些常见的推广方法
  • 合肥大型网站如何推广普通话
  • 高端网站制作软件怎么样推广自己的店铺和产品
  • 无障碍浏览网站怎么做关键词seo排名优化推荐
  • wordpress 247seo推广系统
  • 做深圳门户网站起什么名字好泰州seo外包公司
  • 网站视频上传怎么做百度站长平台论坛
  • wordpress农业模板下载小时seo
  • 做网站语言排名2018发帖推广哪个平台好
  • 销氪crmseo入门讲解
  • 蒙阴哪有做淘宝网站的钓鱼网站制作教程
  • 网站如何做导航条下拉菜单怎么做百度网页