美文网首页
JavaFx 圆角边框图片

JavaFx 圆角边框图片

作者: Ggx的代码之旅 | 来源:发表于2017-11-02 09:34 被阅读480次

群里问道一个JavaFx的需求,如何显示一个圆角边框图片。总不能让原来的图片直接就做成圆角的吧,这肯定不现实。最终在stackoverflow上有大神写出了自己的方案。在此纪录在案——先膜拜一下。原话如下:

If you want to actually round the image itself, it's a bit trickier. You need to apply some code to:

  1. Clip the image to a rounded rectangle.
  2. Snapshot the clipped image.
  3. Store the snapshot image back in the ImageView.
  4. Remove the clip from the ImageView.
  5. Apply the drop shadow effect to the ImageView.

Then you can get something like below:

圆角图片

Some code:

        @FXML
        public void initialize() {
            // set a clip to apply rounded border to the original image.
            Rectangle clip = new Rectangle(
                imageView.getFitWidth(), imageView.getFitHeight()
            );
            clip.setArcWidth(20);
            clip.setArcHeight(20);
            imageView.setClip(clip);

            // snapshot the rounded image.
            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage image = imageView.snapshot(parameters, null);

            // remove the rounding clip so that our effect can show through.
            imageView.setClip(null);

            // apply a shadow effect.
            imageView.setEffect(new DropShadow(20, Color.BLACK));

            // store the rounded image in the imageView.
            imageView.setImage(image);
        }

欢迎共同探讨更多安卓,java,c/c++相关技术QQ群:392154157

相关文章

  • JavaFx 圆角边框图片

    群里问道一个JavaFx的需求,如何显示一个圆角边框图片。总不能让原来的图片直接就做成圆角的吧,这肯定不现实。最终...

  • Image

    直接圆角图片 设置圆角图片度数 设置圆角图片带灰色圆角边框 设置圆角图片带灰色圆角边框带阴影

  • CSS3边框,背景,渐变,过渡,2d变换

    01-边框圆角.html 02-圆角应用.html 03-边框阴影.html 04-边框图片.html 01-背景...

  • CSS边框圆角--跟着李南江学编程

    1.什么是边框圆角? 就是把矩形边框变成圆角边框,就叫做边框圆角。 2.设置边框圆角的格式 2.1 border-...

  • 25.边框圆角渐变

    边框 什么是边框圆角?将直角的边框变为圆角的边框 边框圆角的格式?border-radius: 左上 右上 右下 ...

  • Flutter-Border

    边框(Border) 单侧边框 全部边框 圆角(borderRadius) 全部圆角 单侧圆角 阴影(BoxSha...

  • CSS3边框

    border-radius 设置边框圆角 border-image 用图片作为边框的修饰 box-shadow 边...

  • CSS3-边框属性

    CSS3中支持使用border-radius设置边框的圆角. 设置边框图片 border-image 可以设置边框...

  • 边框 背景

    1 边框 能够创建圆角边框,向矩形添加阴影,使用图片来绘制边框 - 并且不需使用设计软件 对于 border-im...

  • css之border

    css边框属性 通过css3,能够创建圆角边框,向矩形添加阴影,使用图片来绘制边框 border-radius b...

网友评论

      本文标题:JavaFx 圆角边框图片

      本文链接:https://www.haomeiwen.com/subject/fvfopxtx.html