當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageView.setViewport方法代碼示例

本文整理匯總了Java中javafx.scene.image.ImageView.setViewport方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageView.setViewport方法的具體用法?Java ImageView.setViewport怎麽用?Java ImageView.setViewport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.image.ImageView的用法示例。


在下文中一共展示了ImageView.setViewport方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ImagePropertiesSample

import javafx.scene.image.ImageView; //導入方法依賴的package包/類
public ImagePropertiesSample() {
    //we can set image properties directly during creation
    ImageView sample1 = new ImageView(new Image(url, 30, 70, false, true));

    ImageView sample2 = new ImageView(new Image(url));
    //image can be resized to preferred width
    sample2.setFitWidth(200);
    sample2.setPreserveRatio(true);
    
    ImageView sample3 = new ImageView(new Image(url));
    //image can be resized to preferred height
    sample3.setFitHeight(20);
    sample3.setPreserveRatio(true);
    
    ImageView sample4 = new ImageView(new Image(url));
    //one can resize image without preserving ratio between height and width
    sample4.setFitWidth(40);
    sample4.setFitHeight(80);
    sample4.setPreserveRatio(false);
    sample4.setSmooth(true); //the usage of the better filter

    ImageView sample5 = new ImageView(new Image(url));
    sample5.setFitHeight(60);
    sample5.setPreserveRatio(true);
    //viewport is used for displaying the part of image
    Rectangle2D rectangle2D = new Rectangle2D(50, 200, 120, 60);
    sample5.setViewport(rectangle2D);

    //add the imageviews to layout
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    hBox.getChildren().addAll(sample1, sample3, sample4, sample5);

    //show the layout
    VBox vb = new VBox(10);
    vb.getChildren().addAll(hBox, sample2);
    getChildren().add(vb);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:39,代碼來源:ImagePropertiesSample.java

示例2: createIconContent

import javafx.scene.image.ImageView; //導入方法依賴的package包/類
public static Node createIconContent() {
    //TODO better icon?
    ImageView iv = new ImageView(BRIDGE);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    iv.setViewport(new Rectangle2D(0, 85, 330, 330));
    return iv;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:9,代碼來源:ImagePropertiesSample.java

示例3: createIconContent

import javafx.scene.image.ImageView; //導入方法依賴的package包/類
public static Node createIconContent() {
    ImageView iv = new ImageView(BOAT);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    iv.setViewport(new Rectangle2D(90,0,332,332));
    final SepiaTone SepiaTone = new SepiaTone();
    SepiaTone.setLevel(1);
    iv.setEffect(SepiaTone);
    return iv;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:11,代碼來源:SepiaToneSample.java

示例4: updateItem

import javafx.scene.image.ImageView; //導入方法依賴的package包/類
@Override
protected void updateItem(Object item, boolean empty) {
	super.updateItem(item, empty);

	this.setAlignment(Pos.CENTER);

	if (item != null) {
		if (item instanceof String) {
			setText((String) item);
			setGraphic(null);
		} else if (item instanceof Image) {
			setText(null);
			ImageView imageView = new ImageView((Image) item);

			double width = ((Image) item).getWidth();
			double height = ((Image) item).getHeight();
			double x = 0;
			double y = height / 4;

			// define crop in image coordinates:
			Rectangle2D croppedPortion = new Rectangle2D(x, y, width, height / 3);

			imageView.setViewport(croppedPortion);
			imageView.setFitWidth(180);
			imageView.setFitHeight(50);
			imageView.setSmooth(true);
			setGraphic(imageView);
		} else {
			setText(null);
			setGraphic(null);
		}
	}
}
 
開發者ID:Team-Sprout,項目名稱:Clipcon-Client,代碼行數:34,代碼來源:MainScene.java


注:本文中的javafx.scene.image.ImageView.setViewport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。