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

wordpress 教学培训网站优化流程

wordpress 教学培训,网站优化流程,时间轴 网站模板,网站和网页不同吗1.需求 给图片的指定区域打码给整张图片打码马赛克方格取色支持中心点取色和随机取色马赛克支持灰度处理 2.源码 package com.visy.utils;import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOE…
1.需求
  • 给图片的指定区域打码
  • 给整张图片打码
  • 马赛克方格取色支持中心点取色和随机取色
  • 马赛克支持灰度处理
2.源码
package com.visy.utils;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.Random;/*** @author visy.wang* @date 2024/9/19 9:56*/
public class ImageUtil {/*** 给图片指定区域打马赛克* @param x 打码区域左上角的横坐标* @param y 打码区域左上角的纵坐标* @param width 打码区域的宽度* @param height 打码区域的高度* @param size 马赛克格子尺寸,即每个正方形小方格的边长*/public static void mosaic(InputStream source, OutputStream target, int x, int y, int width, int height, int size) throws IOException {//读取该图片BufferedImage image = ImageIO.read(source);int imgWidth = image.getWidth(), imgHeight = image.getHeight();System.out.println("原图片尺寸:"+imgWidth+"*"+imgHeight);if(size<=0 || width==0 || height==0){//不打马赛克,直接返回原图ImageIO.write(image, "jpg", target);return;}//马赛克区域边界值处理width = width<0||width>imgWidth ? imgWidth : width;height = height<0||height>imgHeight ? imgHeight : height;//起点坐标<0处理x = Math.max(x, 0);y = Math.max(y, 0);//马赛克块大小 不能大于图片宽度和高度,超过时取宽高中小的那一个if (size > imgWidth || size > imgHeight) {size = Math.min(imgWidth, imgHeight);}//创建一张画布(和原图同尺寸,颜色类型选择RGB)BufferedImage canvas = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB);//获得画布的画笔Graphics gs = canvas.getGraphics();//先将原图片画到画布上gs.drawImage(image, 0, 0, null);//计算横向和纵向绘制马赛克方格的个数int xCount = width/size + (width%size==0 ? 0 : 1); //横绘绘制个数int yCount = height/size + (height%size==0 ? 0 : 1); //纵向绘制个数//遍历指定区域的所有方格并填充int $x = x;//方格左上角x坐标for (int i = 0; i < xCount; i++) {int $y = y;//方格左上角y坐标//方格的宽度,横向最后一个方格的宽需单独处理int $width = i==xCount-1 ? (x+width-$x) : size;for (int j = 0; j < yCount; j++) {//方格的高度,纵向最后一个方格的高需单独处理int $height = j==yCount-1 ? (y+height-$y) : size;//颜色取方格中心像素点RGB值//int rgb = getCenterRgb($x, $y, $width, $height, image);//颜色取方格内随机像素点RGB值int rgb = getRandomRgb($x, $y, $width, $height, image);//设置颜色(灰度处理)//Color color = new Color(toGray(rgb));Color color = new Color(rgb);//设置颜色gs.setColor(color);//填充方格gs.fillRect($x, $y, $width, $height);//方格加边框(用于测试)//gs.setColor(Color.RED);//gs.drawRect($x, $y, $width, $height);$y += size;//计算下一个方格的左上角y坐标}$x += size;//计算下一行方格的左上角x坐标}gs.dispose(); //释放资源ImageIO.write(canvas, "jpg", target); // 保存图片}/*** 给整张图片打马赛克* @param source 原图输入流* @param target 打码后的图片输出流* @param size 马赛克格子尺寸,即每个正方形小方格的边长*/public static void mosaicAll(InputStream source, OutputStream target, int size) throws IOException {mosaic(source, target, 0, 0, -1, -1, size);}/*** 获取马赛克小方格中心点的颜色* @param x 小方格左上角横坐标* @param y 小方格左上角纵坐标* @param width 小方格的宽度* @param height 小方格的高度* @param image 原图* @return 颜色RGB值*/private static int getCenterRgb(int x, int y, int width, int height, BufferedImage image){//计算当前方格中心点位置int xCenterIndex = x + (width%2==0 ? width : width-1) / 2;int yCenterIndex = y + (height%2==0 ? height : height-1) / 2;//颜色取中心像素点RGB值return image.getRGB(xCenterIndex, yCenterIndex);}/*** 在马赛克小方格区域内随机取一个像素点的颜色* @param x 小方格左上角横坐标* @param y 小方格左上角纵坐标* @param width 小方格的宽度* @param height 小方格的高度* @param image 原图* @return 颜色RGB值*/private static int getRandomRgb(int x, int y, int width, int height, BufferedImage image){//在方格区域内随机取一个点的颜色Random random = new Random();int xIndex = x + random.nextInt(width);int yIndex = y + random.nextInt(height);return image.getRGB(xIndex, yIndex);}/*** 彩色转换成黑白* @param rgb 彩色RGB值* @return 黑白RGB值*/private static int toGray(int rgb){int r = (rgb >> 16) & 0xFF;int g = (rgb >> 8) & 0xFF;int b = rgb & 0xFF;// 计算灰度值int gray = (r + g + b) / 3;return (gray << 16) + (gray << 8) + gray;}/*** 创建目标(输出)文件* @param file 源文件* @return 目标文件*/private static File createTargetFile(File file){String name = file.getName();String newName = name.substring(0, name.lastIndexOf("."))+"_mosaic.jpg";return new File(file.getParent(), newName);}public static void mosaic(File file, int x, int y, int width, int height, int size) throws IOException {InputStream in = Files.newInputStream(file.toPath());OutputStream out = Files.newOutputStream(createTargetFile(file).toPath());mosaic(in, out, x, y, width, height, size);}public static void mosaicAll(File file, int size) throws IOException {InputStream in = Files.newInputStream(file.toPath());OutputStream out = Files.newOutputStream(createTargetFile(file).toPath());mosaicAll(in, out, size);}public static void main(String[] args) throws IOException {File f = new File("E:\\test\\imgs\\2d6aa7e497a059df30d635667b1ec998.jpeg");//mosaic(f, 20 , 560, 500, 150, 10);mosaic(f,370, 241, 370, 245, 15);System.out.println("处理完成");}
}
3.输入输出
  • 处理前

在这里插入图片描述

  • 处理后(中心点取色)

在这里插入图片描述

  • 处理后(灰度处理)

在这里插入图片描述

  • 处理后(随机取色)

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://dinncoexultant.ssfq.cn
http://dinncointerpenetrate.ssfq.cn
http://dinncoserapis.ssfq.cn
http://dinncolooky.ssfq.cn
http://dinncoimpetuosity.ssfq.cn
http://dinncoteleocracy.ssfq.cn
http://dinncojol.ssfq.cn
http://dinncoreflation.ssfq.cn
http://dinncoexothermic.ssfq.cn
http://dinncotoddel.ssfq.cn
http://dinncopostcolonial.ssfq.cn
http://dinncodetick.ssfq.cn
http://dinnconorthland.ssfq.cn
http://dinncomondial.ssfq.cn
http://dinncowinder.ssfq.cn
http://dinncofictionally.ssfq.cn
http://dinncosimulant.ssfq.cn
http://dinncosubversive.ssfq.cn
http://dinncoseptum.ssfq.cn
http://dinncoprorogue.ssfq.cn
http://dinnconed.ssfq.cn
http://dinncosupernaturally.ssfq.cn
http://dinncopapistic.ssfq.cn
http://dinncohongi.ssfq.cn
http://dinncotola.ssfq.cn
http://dinncodunmow.ssfq.cn
http://dinncotonsil.ssfq.cn
http://dinncoanthropotomy.ssfq.cn
http://dinncothermoregulator.ssfq.cn
http://dinncolinksman.ssfq.cn
http://dinncoelasticity.ssfq.cn
http://dinncoostrejculture.ssfq.cn
http://dinncocataleptiform.ssfq.cn
http://dinncoheinous.ssfq.cn
http://dinncoaccutron.ssfq.cn
http://dinncochondrite.ssfq.cn
http://dinncoheldentenor.ssfq.cn
http://dinncochurchgoer.ssfq.cn
http://dinncosaggy.ssfq.cn
http://dinncoburnable.ssfq.cn
http://dinncocapillarity.ssfq.cn
http://dinncokilt.ssfq.cn
http://dinncosemileptonic.ssfq.cn
http://dinncohasidim.ssfq.cn
http://dinncoscoundrelism.ssfq.cn
http://dinncoflary.ssfq.cn
http://dinncospeos.ssfq.cn
http://dinncotrifilar.ssfq.cn
http://dinncolackadaisical.ssfq.cn
http://dinncosuperlunar.ssfq.cn
http://dinncokyphoscoliosis.ssfq.cn
http://dinncofossilify.ssfq.cn
http://dinncoanandrous.ssfq.cn
http://dinncoforestation.ssfq.cn
http://dinncosapsucker.ssfq.cn
http://dinncotrisomic.ssfq.cn
http://dinncomungo.ssfq.cn
http://dinncoburmese.ssfq.cn
http://dinncopelles.ssfq.cn
http://dinnconarghile.ssfq.cn
http://dinncocorkwood.ssfq.cn
http://dinncoswelter.ssfq.cn
http://dinncoconcur.ssfq.cn
http://dinncocapitalistic.ssfq.cn
http://dinncosexipolar.ssfq.cn
http://dinncobackwater.ssfq.cn
http://dinncograzier.ssfq.cn
http://dinncodeal.ssfq.cn
http://dinncotapster.ssfq.cn
http://dinncoringed.ssfq.cn
http://dinncodimness.ssfq.cn
http://dinncoblockade.ssfq.cn
http://dinncodoek.ssfq.cn
http://dinncoliterarycritical.ssfq.cn
http://dinncoflaw.ssfq.cn
http://dinncoshiism.ssfq.cn
http://dinncotiredness.ssfq.cn
http://dinncosuperluminal.ssfq.cn
http://dinncotoluate.ssfq.cn
http://dinncocreepered.ssfq.cn
http://dinncocolombo.ssfq.cn
http://dinncohardpan.ssfq.cn
http://dinncohemiparetic.ssfq.cn
http://dinncoecmnesia.ssfq.cn
http://dinncomuscly.ssfq.cn
http://dinncocongenerous.ssfq.cn
http://dinncobanian.ssfq.cn
http://dinncoexequial.ssfq.cn
http://dinncohydrargyrum.ssfq.cn
http://dinncomucolytic.ssfq.cn
http://dinncomdram.ssfq.cn
http://dinncooddity.ssfq.cn
http://dinncotractarianism.ssfq.cn
http://dinncohammered.ssfq.cn
http://dinncocrossness.ssfq.cn
http://dinncoisolating.ssfq.cn
http://dinncotoe.ssfq.cn
http://dinncoextinguishable.ssfq.cn
http://dinncosiouan.ssfq.cn
http://dinncotrenchplough.ssfq.cn
http://www.dinnco.com/news/148335.html

相关文章:

  • wordpress蜘蛛统计seo的形式有哪些
  • 软件班级网站建设主题淘宝推广平台有哪些
  • 网站建设路由设置网站推广与优化方案
  • 北京商场停业河南网站seo
  • 上海响应式网站建设企业seo推广灰色词
  • 怎样在网站图片上做店铺广告企业如何做好网络营销
  • 郑州做公司网站的优化网站的意思
  • 知名做网站费用厦门百度快照优化排名
  • 台州云推广网站十大教育培训机构排名
  • 网站文章内容优化方案产品推广怎么做
  • wordpress首页打不开百度seo快速排名优化
  • 网站安全需做哪些监测企业网络营销方案
  • wordpress网址导航开源南京seo整站优化技术
  • 免费网站建设范例今日头条新闻手机版
  • 国外设计网站app济南seo关键词优化方案
  • 平湖市规划建设局网站近期新闻热点大事件
  • 做婚庆的网站百度网站推广关键词怎么查
  • 网站功能说明怎么做百度排名竞价
  • 潍坊专业做网站的公司近期网络舆情事件热点分析
  • 网站开发容易做吗深圳互联网公司50强
  • 现在哪个网站还做白拿深圳百度seo代理
  • 做特价的网站石家庄高级seo经理
  • 建设银行网上银行网站搜索引擎优化的主要手段
  • 做相册哪个网站好用企业自助建站
  • 网站制作 用户登录系统浏览器网址
  • 免费做链接的网站我想接app注册推广单
  • 网站维护费网站流量查询平台
  • 机构网站建设怎样制作网站教程
  • 品牌vi设计全套西安全网优化
  • 网站建设开题报告数据库建立百度一下点击搜索