How to change color of image in JavaFX

Eeliya

I have a PNG image like this:

png image

I want to change image to something like this:

enter image description here

How can I do this in JavaFX?

jewelsea

As you don't care if it is a vector shape or a bitmap, I'll just outline solutions using a bitmap here. If you actually wanted a vector shape, I believe you would need to work with vector input to get a good result.


Use a ColorAdjust effect with the brightness set to minimum (-1). Cache the result for SPEED.

speed

Here is a sample which creates a shadow outline of an image:

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.*;
import javafx.stage.Stage;

public class Shadow extends Application {
    @Override 
    public void start(Stage stage) throws Exception {
        ImageView imageView = new ImageView(
            new Image(
                "http://i.stack.imgur.com/jbT1H.png"
            )
        );

        ColorAdjust blackout = new ColorAdjust();
        blackout.setBrightness(-1.0);

        imageView.setEffect(blackout);
        imageView.setCache(true);
        imageView.setCacheHint(CacheHint.SPEED);

        stage.setScene(new Scene(new Group(imageView)));
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch();
    }
}

Here is another sample which adjusts the color of an image, hover over smurfette to make her blush.

smurfette blushing smurfette

import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.image.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Shadow extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        Image image = new Image(
                "http://icons.iconarchive.com/icons/designbolts/smurfs-movie/128/smurfette-icon.png"
        );

        ImageView imageView = new ImageView(image);
        imageView.setClip(new ImageView(image));

        ColorAdjust monochrome = new ColorAdjust();
        monochrome.setSaturation(-1.0);

        Blend blush = new Blend(
                BlendMode.MULTIPLY,
                monochrome,
                new ColorInput(
                        0,
                        0,
                        imageView.getImage().getWidth(),
                        imageView.getImage().getHeight(),
                        Color.RED
                )
        );

        imageView.effectProperty().bind(
                Bindings
                    .when(imageView.hoverProperty())
                        .then((Effect) blush)
                        .otherwise((Effect) null)
        );

        imageView.setCache(true);
        imageView.setCacheHint(CacheHint.SPEED);

        stage.setScene(new Scene(new Group(imageView), Color.AQUA));
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch();
    }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to change web browser's tab bar background color or image?

분류에서Dev

How to change button color

분류에서Dev

Change color of a specific region in eye image [Matlab]

분류에서Dev

How to change the color of *just* the header?

분류에서Dev

How to change color of CCDrawNode component?

분류에서Dev

Change SVG image color using Css or do it manually in SVG file

분류에서Dev

How to change an image on mouse over?

분류에서Dev

How to dynamically change SVG fill color?

분류에서Dev

How to change default selection color of a ListView?

분류에서Dev

How to change the color of the text of a label in Xcode

분류에서Dev

How to change a font/background color in transparent windows?

분류에서Dev

How to find and change color of specific word in string

분류에서Dev

How to change the color of a senders parent on event?

분류에서Dev

How can i change hyperlink color with JQuery?

분류에서Dev

How to Change Font Color based on Conditional?

분류에서Dev

How to change the color of the text in below code?

분류에서Dev

How to change the color of different files in ls

분류에서Dev

How to change the Foreground Color of ListView Selected Item

분류에서Dev

How to change the color of a touched region in ImageView?

분류에서Dev

How to change tint color of a rightCalloutAccessory on Mapbox?

분류에서Dev

How to replace color of PNG image using CSS?

분류에서Dev

how to set png image color in winjs

분류에서Dev

How to change image in a collection view cell

분류에서Dev

Swift: How to change NSImage image source?

분류에서Dev

How to Change CommandField ButtonType Image Width and Height

분류에서Dev

How to change the width of jbox-image-gallery?

분류에서Dev

How to change image of a JLabel in another thread

분류에서Dev

How to change color of the bubble (under cursor) on EditText in Flutter

분류에서Dev

How to make a Widget change color briefly like a button

Related 관련 기사

  1. 1

    How to change web browser's tab bar background color or image?

  2. 2

    How to change button color

  3. 3

    Change color of a specific region in eye image [Matlab]

  4. 4

    How to change the color of *just* the header?

  5. 5

    How to change color of CCDrawNode component?

  6. 6

    Change SVG image color using Css or do it manually in SVG file

  7. 7

    How to change an image on mouse over?

  8. 8

    How to dynamically change SVG fill color?

  9. 9

    How to change default selection color of a ListView?

  10. 10

    How to change the color of the text of a label in Xcode

  11. 11

    How to change a font/background color in transparent windows?

  12. 12

    How to find and change color of specific word in string

  13. 13

    How to change the color of a senders parent on event?

  14. 14

    How can i change hyperlink color with JQuery?

  15. 15

    How to Change Font Color based on Conditional?

  16. 16

    How to change the color of the text in below code?

  17. 17

    How to change the color of different files in ls

  18. 18

    How to change the Foreground Color of ListView Selected Item

  19. 19

    How to change the color of a touched region in ImageView?

  20. 20

    How to change tint color of a rightCalloutAccessory on Mapbox?

  21. 21

    How to replace color of PNG image using CSS?

  22. 22

    how to set png image color in winjs

  23. 23

    How to change image in a collection view cell

  24. 24

    Swift: How to change NSImage image source?

  25. 25

    How to Change CommandField ButtonType Image Width and Height

  26. 26

    How to change the width of jbox-image-gallery?

  27. 27

    How to change image of a JLabel in another thread

  28. 28

    How to change color of the bubble (under cursor) on EditText in Flutter

  29. 29

    How to make a Widget change color briefly like a button

뜨겁다태그

보관