2014-06-03 4 views
3

복잡한 클리핑 이미지에 엠보싱 효과 (bump mapped라고도 함)를 추가하려고합니다. (즉, 퍼즐 조각) 이것은 픽셀 단위의 작업으로 수행 될 수 있지만 매우 비쌉니다 : 클리핑의 정확한 형태는 런타임에 결정되므로 범프 맵조차도 런타임으로 생성되어야합니다. 이것은 거의 잘 작동하는 조명 효과Javafx에서 클리핑 된 이미지에 조명 효과 추가

// Create clipping 
pieceClip = createPiece(topEdge, leftEdge, bottomEdge, rightEdge); 
pieceClip.setFill(Color.WHITE); 
pieceClip.setStroke(null); 

// Create clipped image view 
imageView.setImage(image); 
imageView.setClip(pieceClip); 

// Create ambient light 
Light.Distant light = new Light.Distant(); 
light.setAzimuth(-135.0); 

// Create lighting effect 
Lighting lighting = new Lighting(); 
lighting.setLight(light); 
lighting.setSurfaceScale(4.0); 

// Create shape to apply lighting on (the shape is the same as the clipping) 
Shape pieceStroke1 = createPiece(topEdge, leftEdge, bottomEdge, rightEdge); 
pieceStroke1.setFill(new Color(1, 1, 1, 0.4)); 
pieceStroke1.setStroke(null); 

// Apply lighting 
pieceStroke1.setEffect(lighting); 

// Add clipped image and lighting overlay to the shape 
getChildren().addAll(imageView, pieceStroke1); 

:

자바 FX의 조명 효과가 아웃 - 오브 - 박스와 유사한 효과를 제공하지만

, 그것은 부작용이 다음에 의한 오버레이가 흰색이고 반투명 한 경우에만 이미지가 어두워지고 (안개가 자욱하고 안개가 생기지 않습니다.)

블렌드 (COLOR_BURN, DARKEN 등)를 사용하여 이미지 색상을 복원하려고했지만 이러한 효과가 적용되지 않아서 실패했습니다.

이미지 채도는 어떻게 예약 할 수 있습니까? 그렇지만 양각 효과를 적용 할 수 있습니까?

나는 그것을 어떻게 몇 가지 아이디어를 가지고,하지만 난 하나 일 것입니다 아무 생각이 없다 :

  1. 이미지에 직접 조명을 적용합니다. 복제되지 않은 이미지에 조명이 적용 되었기 때문에 실패했습니다.
  2. 이미지 또는 조명 오버레이에 혼합 효과를 적용하여 채도 감소 보정 내 효과로 인해 실패했습니다.
  3. 조명 영향을받는 영역 만 덮기 위해 오버레이 모양 잘라 내기 어렵고 비용이 많이 드는 베 지어 곡선을 옵셋해야합니다.
  4. 조명 효과 강도를 따르기 위해 오버레이 모양 알파를 변경합니다.

모든 아이디어에 깊이 감사드립니다.

답변

3

해결

효과는 체인의 Lighting 취지 ColorAdjust 효과를 적용한다.

조명 효과는 이미지의 외관과 색상을 사용자가 무엇을하든 관계없이 어느 정도 변경합니다 (조명 효과와 동일하므로). 추가 색상 조정을 적용하면 이미지를 얻을 수 있습니다. 인식 할 수있는 정도로 원래의 색칠에 꽤 가깝습니다.

이미지의 모양을 조정해야하는 경우 잘린 이미지를 스냅하고 Border-Radius and Shadow on ImageView에 대한 답변에서 설명한대로 원하는 경우 스냅 사진에 효과를 적용하십시오.답에 대한

// increase brightness and contrast. 
ColorAdjust brightLight = new ColorAdjust(0, 0, .25, 0.25); 

// chain in your lighting effect. 
brightLight.setInput(lighting); 

// apply the chained effect to your image. 
ImageView litAdjusted = new ImageView(image); 
litAdjusted.setEffect(brightLight); 

실행 샘플

herebedragons

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.*; 
import javafx.scene.control.*; 
import javafx.scene.effect.*; 
import javafx.scene.image.*; 
import javafx.scene.layout.HBox; 
import javafx.scene.paint.Color; 
import javafx.scene.text.TextAlignment; 
import javafx.stage.Stage; 

// Java 8 code 
public class HereBeDragons extends Application { 

    @Override public void start(final Stage stage) { 
     Image image  = new Image(imageLoc); 
     Image clipImage = new Image(CLIP_IMAGE_LOC); 

     ImageView plain = new ImageView(image); 

     ImageView lit = new ImageView(image); 
     Lighting lighting = createLighting(); 
     lit.setEffect(lighting); 

     ImageView litAdjusted = new ImageView(image); 
     ColorAdjust brightLight = new ColorAdjust(0, 0, .25, 0.25); 
     brightLight.setInput(lighting); 
     litAdjusted.setEffect(brightLight); 

     plain.setClip(new ImageView(clipImage)); 
     SnapshotParameters params = new SnapshotParameters(); 
     params.setFill(Color.TRANSPARENT); 
     WritableImage clippedImage = plain.snapshot(params, null); 
     ImageView litAdjustedClip = new ImageView(clippedImage); 
     litAdjustedClip.setEffect(brightLight); 
     plain.setClip(null); 

     HBox layout = new HBox(
       10, 
       new CaptionedImage(plain,  "Plain"), 
       new CaptionedImage(lit,   "Lit"), 
       new CaptionedImage(litAdjusted, "Lit and Adjusted"), 
       new CaptionedImage(litAdjustedClip, "Clipped,\nLit and Adjusted") 
     ); 
     layout.setPadding(new Insets(20)); 
     layout.setStyle("-fx-background-color: lightblue;"); 

     stage.setTitle("Here be Dragons"); 
     stage.setScene(new Scene(layout, Color.LIGHTBLUE)); 
     stage.setResizable(false); 
     stage.show(); 
    } 

    private Lighting createLighting() { 
     // Create ambient light 
     Light.Distant light = new Light.Distant(); 
     light.setAzimuth(-135.0); 

     // Create lighting effect 
     Lighting lighting = new Lighting(); 
     lighting.setLight(light); 
     lighting.setSurfaceScale(4.0); 

     return lighting; 
    } 

    private class CaptionedImage extends Label { 
     public CaptionedImage(ImageView imageView, String caption) { 
      setText(caption); 
      setGraphic(imageView); 
      setContentDisplay(ContentDisplay.TOP); 
      setTextAlignment(TextAlignment.CENTER); 

      setStyle(
        "-fx-text-fill: midnightblue; " + 
        "-fx-font-size: 16px; " + 
        "-fx-font-family: palatino; " + 
        "-fx-font-style: italic;" 
      ); 
     } 
    } 

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

    private static final String imageLoc = 
     "http://icons.iconarchive.com/icons/custom-icon-design/round-world-flags/128/Wales-icon.png";  
    // icon license: Free for non-commercial use. 
    // Buy commercial license here: 
    // http://www.customicondesign.com/free-icons/flag-icon-set/flat-round-world-flag-icon-set 

    private static final String CLIP_IMAGE_LOC = 
      "http://icons.iconarchive.com/icons/gpritiranjan/simple-christmas/128/star-icon.png"; 
    // star icon license: freeware, commercial usage allowed. 
} 
+0

감사합니다. 거의 완벽하지만 문제의 절반 만 해결합니다. 해결 방법은 이미지 자체에 조명 (및 수정)을 적용하지만 이미지를 잘라내어 효과를 전체 이미지로 전달하기 때문에 사용할 수 없습니다. 이것이 오버레이 ('pieceStroke1')를 사용해야하는 이유입니다. 오버레이에 솔루션을 적용하려했지만 작동하지 않습니다. :-( 어쨌든 문제의 첫 부분을 해결했기 때문에 답을 얻었습니다. 조명 색상을 수정하는 방법 – Balage1551

+1

잘라낸 이미지를 스냅 한 다음 원하는대로 스냅 사진에 효과를 적용하십시오. – jewelsea

+0

jewelsea , 당신의 대답은 내 질문의 두 번째 부분에 대한 해결책을 주었다. [이 다른 질문에 StackOverflow] (http://stackoverflow.com/questions/20489908/border-radius-and-shadow-on-imageview) 내게 준 info (스냅 샷 방법). 감사합니다! –

관련 문제