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

舟山网站开发网站增加二级域名

舟山网站开发,网站增加二级域名,中国建设银行手机wap网站,给女生做网站最近网上看到两种不同的java图片缩略图的绘制方案第一种#xff0c;使用Graphics().drawImage按照一定的比例重新绘制图像。Java代码package com.image.suoluetu;import java.io.*;import java.awt.*;import java.awt.image.*;import com.sun.image.codec.jpeg.*;public class…最近网上看到两种不同的java图片缩略图的绘制方案第一种使用Graphics().drawImage按照一定的比例重新绘制图像。Java代码package com.image.suoluetu;import java.io.*;import java.awt.*;import java.awt.image.*;import com.sun.image.codec.jpeg.*;public class DrawImage {private String destFile;private int width;private int height;private Image img;public DrawImage(String fileName) throws IOException {File _file  new File(fileName); // 读入文件_file.getName();this.destFile  D:/dage2.jpg;// this.srcFile.substring(0,// this.srcFile.lastIndexOf(.))// _s.jpg;img  javax.imageio.ImageIO.read(_file); // 构造Image对象width  img.getWidth(null); // 得到源图宽height  img.getHeight(null); // 得到源图长}/*** /**** param args*/public void resize(int w, int h) throws IOException {try {BufferedImage _image  new BufferedImage(w, h,BufferedImage.TYPE_INT_RGB);_image.getGraphics().drawImage(img, 0, 0, w, h, null); // 绘制缩小后的图FileOutputStream newimageout  new FileOutputStream(destFile); // 输出到文件流/** JPEGImageEncoder 将图像缓冲数据编码为 JPEG 数据流。该接口的用户应在 Raster 或* BufferedImage 中提供图像数据在 JPEGEncodeParams 对象中设置必要的参数 并成功地打开* OutputStream(编码 JPEG 流的目的流)。JPEGImageEncoder 接口可 将图像数据编码为互换的缩略* JPEG 数据流该数据流将写入提供给编码器的 OutputStream 中。* 注意com.sun.image.codec.jpeg 包中的类并不属于核心 Java API。它们属于 Sun 发布的 JDK* 和 JRE 产品的组成部分。虽然其它获得许可方可能选择发布这些类但开发人员不能寄 希望于从非 Sun* 实现的软件中得到它们。我们期望相同的功能最终可以在核心 API 或标准扩 展中得到。*/JPEGImageEncoder encoder  JPEGCodec.createJPEGEncoder(newimageout);encoder.encode(_image); // 近JPEG编码newimageout.close();} catch (Exception ex) {ex.printStackTrace();}}/*** 按照固定的比例缩放图片** param t*            double 比例* throws IOException*/public void resize(double t) throws IOException {int w  (int) (width * t);int h  (int) (height * t);resize(w, h);}/*** 以宽度为基准等比例放缩图片** param w*            int 新宽度* throws IOException*/public void resizeByWidth(int w) throws IOException {int h  (int) (height * w / width);resize(w, h);}/*** 以高度为基准等比例缩放图片** param h*            int 新高度* throws IOException*/public void resizeByHeight(int h) throws IOException {int w  (int) (width * h / height);resize(w, h);}/*** 按照最大高度限制生成最大的等比例缩略图** param w*            int 最大宽度* param h*            int 最大高度* throws IOException*/public void resizeFix(int w, int h) throws IOException {if (width / height  w / h) {resizeByWidth(w);} else {resizeByHeight(h);}}/*** 设置目标文件名 setDestFile** param fileName*            String 文件名字符串*/public void setDestFile(String fileName) throws Exception {if (!fileName.endsWith(.jpg)) {throw new Exception(Dest File Must end with \.jpg\.);}destFile  fileName;}/*** 获取目标文件名 getDestFile*/public String getDestFile() {return destFile;}/*** 获取图片原始宽度 getSrcWidth*/public int getSrcWidth() {return width;}/*** 获取图片原始高度 getSrcHeight*/public int getSrcHeight() {return height;}public static void main(String[] args) {// TODO Auto-generated method stubtry {DrawImage ccc  new DrawImage(D:/dage.jpg);ccc.resizeFix(600, 400);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}第二种使用仿射转换的技术进行图片绘制。Java代码package com.image.suoluetu;import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.io.File;import java.awt.image.AffineTransformOp;import java.awt.geom.AffineTransform;public class AffineTransImage {public static void main (String argv[]) {try {File fi  new File(D:/dage.jpg); //大图文件File fo  new File(D:/dagex.jpg); //将要转换出的小图文件int nw  500;/*AffineTransform 类表示 2D 仿射变换它执行从 2D 坐标到其他 2D坐标的线性映射保留了线的“直线性”和“平行性”。可以使用一系列平移、缩放、翻转、旋转和剪切来构造仿射变换。*/AffineTransform transform  new AffineTransform();BufferedImage bis  ImageIO.read(fi); //读取图片int w  bis.getWidth();int h  bis.getHeight();//double scale  (double)w/h;int nh  (nw*h)/w ;double sx  (double)nw/w;double sy  (double)nh/h;transform.setToScale(sx,sy); //setToScale(double sx, double sy) 将此变换设置为缩放变换。System.out.println(w    h);/** AffineTransformOp类使用仿射转换来执行从源图像或 Raster 中 2D 坐标到目标图像或*  Raster 中 2D 坐标的线性映射。所使用的插值类型由构造方法通过*  一个 RenderingHints 对象或通过此类中定义的整数插值类型之一来指定。如果在构造方法中指定了 RenderingHints 对象则使用插值提示和呈现的质量提示为此操作设置插值类型。要求进行颜色转换时可以使用颜色呈现提示和抖动提示。 注意务必要满足以下约束源图像与目标图像必须不同。 对于 Raster 对象源图像中的 band 数必须等于目标图像中的 band 数。*/AffineTransformOp ato  new AffineTransformOp(transform,null);BufferedImage bid  new BufferedImage(nw,nh,BufferedImage.TYPE_3BYTE_BGR);/** TYPE_3BYTE_BGR 表示一个具有 8 位 RGB 颜色分量的图像* 对应于 Windows 风格的 BGR 颜色模型具有用 3 字节存* 储的 Blue、Green 和 Red 三种颜色。*/ato.filter(bis,bid);ImageIO.write(bid,jpeg,fo);} catch(Exception e) {e.printStackTrace();}}}
http://www.yutouwan.com/news/40961/

相关文章:

  • 阿里巴巴网站图片如何做白国外空间
  • 做网站个网站要多少钱网站建设流程报告
  • 郑州网站搭建的公司苏州手机网站建设服务
  • 苏州高端网站网站关键词排名批量查询
  • 计算机毕设代做网站wordpress悬赏功能实现
  • 如何查找网站备案h5制作成品
  • wordpress网站维护教程网站如何做搜索引擎
  • 网站建站时间上海招标网站
  • 代做动画毕业设计的网站建筑工程公司名字起名大全
  • 淘宝客自己做网站吗西安百度关键词包年
  • 宜宾网站开发招聘做网站简单还是做app简单
  • wordpress md晋城网站seo
  • 手机网站建设开什么类型的票常德小程序开发公司
  • 南京江宁网站制作公司上海网站建设哪
  • 建立网站服务器免费制作自己的网页
  • 设计师找素材的网站彩视音乐相册制作下载安装
  • 开锁公司做网站企业展示厅设计效果图
  • 做网站需要服务器查询吗网站设计开发软件有哪些
  • 毕设做的网站可以用模板改吗怎么建立网站
  • 有些人做网站不用钱的 对吗如何推广网址链接
  • 网站建设中最重要的树莓派3 部署wordpress
  • 网站百度推广怎么做的成都展示型网页设计公司
  • 重庆网站备案公司更换网站需要怎么做
  • 给关亨做网站的设计公司代做设计网站
  • 自己设置网站怎么做网站页面设计合同
  • 网站后台设置应注意什么企业网站建设存在的不足
  • 网站建设教程 冰美人视频分分作网站
  • 自己做的网站网页打开速度慢莱州人才招聘网
  • 网站建设百度社交型网站首页面设计分析
  • asp开源企业网站教程网站制作出租