zoukankan      html  css  js  c++  java
  • 图片处理

    /**
    * 缩小或放大图片
    * @param data 图片的byte数据
    * @param w 需要缩到的宽度
    * @param h 需要缩到高度
    * @return 缩放后的图片的byte数据
    */
    private byte[] ChangeImgSize(byte[] data, int nw, int nh){
    byte[] newdata = null;
    try{
    BufferedImage bis = ImageIO.read(new ByteArrayInputStream(data));
    int w = bis.getWidth();
    int h = bis.getHeight();
    double sx = (double) nw / w;
    double sy = (double) nh / h;
    AffineTransform transform = new AffineTransform();
    transform.setToScale(sx, sy);
    AffineTransformOp ato = new AffineTransformOp(transform, null);
    //原始颜色
    BufferedImage bid = new BufferedImage(nw, nh, BufferedImage.TYPE_3BYTE_BGR);
    ato.filter(bis, bid);

    //转换成byte字节
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bid, "jpeg", baos);
    newdata = baos.toByteArray();

    }catch(IOException e){
    e.printStackTrace();
    }
    return newdata;
    }

    void buff2Image(byte[] b,String tagSrc) throws Exception
    {
    try {
    FileOutputStream fout = new FileOutputStream(tagSrc);
    //将字节写入文件
    fout.write(b);
    fout.close();
    } catch (Exception e) {
    // TODO: handle exception
    }
    }

  • 相关阅读:
    动网16位gb2312md5加密
    开发windows7侧边栏小工具
    MVC文档地址
    关闭FCNs(文件修改监控)
    内存管理
    android笔记一(Button)
    android笔记五ImageButton
    android笔记三FrameLayout
    linux内核各组件的功能介绍
    C++面试题
  • 原文地址:https://www.cnblogs.com/zhoading/p/8670056.html
Copyright © 2011-2022 走看看