java jwt图形设计总结(二)

原创
2019/08/02 17:41
阅读数 190

#java jwt图形设计总结(二)

创建透明图层方式

  • 方式一
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    BufferedImageGraphicsConfig config = BufferedImageGraphicsConfig.getConfig(bufferedImage);
    bufferedImage = config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
  • 方式二
    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bufferedImage.createGraphics();
    bufferedImage = graphics.getDeviceConfiguration()
      .createCompatibleImage(width, height, Transparency.TRANSLUCENT);
  • 方式三
    ColorModel cm = ColorModel.getRGBdefault();
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);
    BufferedImage bufferedImage = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

创建图形

  • 画圆形
    double centerX=1000/2;
    double centerY=1000/2;
    double conerX=centerX+100;
    double conerY=centerY+100;
    Ellipse2D circle=new Ellipse2D.Double();
    double radius=Point2D.distance(centerX, centerY, conerX, conerY);
    circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
    graphics.draw(circle);
  • 画正方形
    double centerX=1000/2;
    double centerY=1000/2;
    double conerX=centerX+100;
    double conerY=centerY+50;
    Rectangle2D rect =new Rectangle2D.Double();
    rect.setFrameFromCenter(centerX,centerY,conerX,conerY);
  • 画椭圆
    double centerX=1000/2;
    double centerY=1000/2;
    double conerX=centerX+100;
    double conerY=centerY+50;
    Rectangle2D rect =new Rectangle2D.Double();
    rect.setFrameFromCenter(centerX,centerY,conerX,conerY);
    Ellipse2D ellipse=new Ellipse2D.Double();
    ellipse.setFrame(rect);
  • 画线
    Line2D line= new Line2D.Double(conerX,conerY,conerX-200,conerY-200);
  • 多边形
int px1[]={50,90,10,50};//首末点相重,才能画多边形
int py1[]={10,50,50,10};
int px2[]={140,180,170,180,140,100,110,140};
int py2[]={5,25,35,45,65,35,25,5};
g.setColor(Color.blue);
g.fillPolygon(px1,py1,4);
g.setColor(Color.red);
g.drawPolygon(px2,py2,9);
  • 画弧线
g.drawArc(10,40,90,50,0,180);//画圆弧线

抠图

    BufferedImage inputImage = ImageIO.read(new File("/Users/manager/Desktop/tupian.png"));
    Rectangle2D rectangle = new Rectangle(0,0,inputImage.getWidth(),inputImage.getHeight());
    TexturePaint tPaint = new TexturePaint(inputImage,rectangle);
    BufferedImage bufferedImage = new BufferedImage(100,100,BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g = bufferedImage.createGraphics();
    g.setPaint(tPaint);//填充颜色可以使用g.setColor(new Color(0,204,255))方法替换
    //如果需要设置透明度,添加这句代码
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC,0.5f));
    g.fillPolygon(new int[]{0,100,100,0},new int[]{0,0,100,100},4);
    g.dispose();
    ImageIO.write(bufferedImage,"png",new File("/Users/manager/Desktop/tupian3.png"));

消除矩形

//消除文字锯齿
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//消除画图锯齿
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部