這裏是我想要使用一個簡化圖像加載過程的構造函數的問題。你需要做的只是一個文件路徑。如何使用構造函數將對象設置爲現有對象?
有可能通過繼承來做到這一點,或者我是否需要創建一個新的緩衝圖像對象? 這裏是代碼的理念,使其更容易理解。
public class specialImage extends BufferedImage {
specialImage(String path) {
super();
this = ImageIO.read(new File(Path)); // <--- how can i Do this in java.
}
}
OR我應執行以下操作
class specialImage{
BufferedImage manipulator;
specialImage (String path) {
manpiulator = ImageIO.read(new File(path));
}
}
------------------------ EDIT 1: ------------------------- 我試圖避免返回。我想創建一系列可以操作specialImage類的函數。像
specialImage objectName = new specialImage(FILE_PATH);
objectName.toGrayscale();
objectName.specialTransformation();
//While still using the BufferedImage class, i.e.,
objectName.getRaster();
「_他們沒有提到真實的內存位置,這允許垃圾收集來壓縮內存,而不需要重寫未知數量的引用。」 - 這種情況幾十年來一直沒有發生。在32位上,引用是指針。在64位上,除非使用壓縮的OOPS,否則它們是指針。無論如何,GC確實需要在對象移動時重寫所有引用。 – Doradus 2016-07-20 02:16:38