通過 Java 轉到 DICOM
構建您自己的 Java 應用程序以使用服務器端 API 合併 DICOM 文件。
如何使用 Java 合併 DICOM 文件
如果您想讓您的創造力盡情發揮,那麼現在就是使用圖像拼貼的時候了。即使源文件格式不同,此功能也允許您合併照片和圖像。吸引人們注意您的作品集的一個好方法是使用帶有重複圖像或圖案的照片壁紙。在這種情況下,可以在水平和垂直方向上組合圖像。如果您需要演示處理文件的結果,您可以輕鬆合併兩個圖像:應用照片效果之前和之後。為了合併 DICOM 文件,我們將使用 Aspose.Imaging for Java API 是一個功能豐富、功能強大 易於使用的 Java 平台圖像處理和轉換 API。您可以直接從 Maven 並通過將以下配置添加到 pom.xml 將其安裝在基於 Maven 的項目中。
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
通過 Java 合併 DICOM 的步驟
你需要 aspose-imaging-version-jdk16.jar 在您自己的環境中嘗試以下工作流程。
- 使用 Image.load 方法加載 DICOM 文件
- 將圖像組合成新的圖像
- 將裁剪後的圖像以 Aspose.Imaging 支持的格式保存到光盤
系統要求
所有主要操作系統都支持 Java 的 Aspose.Imaging。只需確保您具有以下先決條件。
- 已安裝 JDK 1.6 或更高版本。
合併 DICOM 圖像 - Java
import com.aspose.imaging.IMultipageImage; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.RasterImage; | |
import com.aspose.imaging.VectorImage; | |
import com.aspose.imaging.fileformats.tiff.TiffFrame; | |
import com.aspose.imaging.fileformats.tiff.TiffImage; | |
import com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat; | |
import com.aspose.imaging.imageoptions.PdfOptions; | |
import com.aspose.imaging.imageoptions.TiffOptions; | |
import java.io.File; | |
import java.io.FilenameFilter; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
// Test directory should have source images to merge | |
String TestDirectory = "D:\\Many2One\\"; | |
// Source file mask, could vary depending on image format (i.e. *.png, *.jpg, *.dicom, *., *.tiff, *.gif etc) | |
final String fileMask = ".png"; | |
List<Image> singles = new ArrayList<Image>(); | |
List<Image> images = new ArrayList<Image>(); | |
try | |
{ | |
int maxWidth = 0; | |
int maxHeight = 0; | |
File[] files = new File(TestDirectory).listFiles(new FilenameFilter() | |
{ | |
@Override | |
public boolean accept(File dir, String name) | |
{ | |
return name.endsWith(fileMask); | |
} | |
}); | |
if (files == null) | |
{ | |
return; | |
} | |
for (File file : files) | |
{ | |
Image image = Image.load(file.getAbsolutePath()); | |
if (image.getWidth() > maxWidth) | |
{ | |
maxWidth = image.getWidth(); | |
} | |
if (image.getHeight() > maxHeight) | |
{ | |
maxHeight = image.getHeight(); | |
} | |
if (image instanceof VectorImage) | |
{ | |
throw new UnsupportedOperationException("Vector images is not supported by these code snippet. Please look at vector to booklet example to get the implementation idea."); | |
} | |
if (image instanceof IMultipageImage) | |
{ | |
Collections.addAll(singles, ((IMultipageImage) image).getPages()); | |
} | |
else | |
{ | |
singles.add(image); | |
} | |
images.add(image); | |
} | |
if (singles.isEmpty()) | |
{ | |
return; | |
} | |
String outputPath1 = TestDirectory + "multiframe.tiff"; | |
String outputPath2 = TestDirectory + "multipage.pdf"; | |
try (TiffImage tiffImage = new TiffImage(new TiffFrame((RasterImage) singles.get(0)))) | |
{ | |
for (int i = 1; i < singles.size(); i++) | |
{ | |
tiffImage.addPage((RasterImage) singles.get(i)); | |
} | |
// Save as muti frame tiff | |
tiffImage.save(outputPath1, new TiffOptions(TiffExpectedFormat.TiffJpegRgb)); | |
// Worry about Pdf ? That's it! | |
tiffImage.save(outputPath2, new PdfOptions()); | |
} | |
} | |
finally | |
{ | |
singles.clear(); | |
for (Image image : images) | |
{ | |
image.close(); | |
} | |
images.clear(); | |
} |
關於 Java API 的 Aspose.Imaging
Aspose.Imaging API 是一種圖像處理解決方案,用於在應用程序中創建、修改、繪製或轉換圖像(照片)。它提供:跨平台的圖像處理,包括但不限於各種圖像格式之間的轉換(包括統一的多頁或多幀圖像處理)、繪圖等修改、使用圖形基元、轉換(調整大小、裁剪、翻轉和旋轉) 、二值化、灰度、調整)、高級圖像處理功能(過濾、抖動、遮罩、去偏斜)和內存優化策略。它是一個獨立的庫,不依賴任何軟件進行圖像操作。可以在項目中使用原生 API 輕鬆添加高性能圖像轉換功能。這些是 100% 私有的本地 API,圖像在您的服務器上處理。通過在線應用合併 DICOM
通過訪問我們的 Live Demos 網站 合併 DICOM 文檔。 現場演示有以下好處
DICOM 什麼是 DICOM 文件格式
DICOM 是 Digital Imaging and Communications in Medicine 的首字母縮寫詞,屬於醫學信息學領域。 DICOM 是文件格式定義和網絡通信協議的結合。 DICOM 使用 .DCM 擴展名。 .DCM 以兩種不同的格式存在,即格式 1.x 和格式 2.x。 DCM Format 1.x 還提供兩個普通版本和擴展版本。 DICOM 用於集成來自不同供應商的打印機、服務器、掃描儀等醫療成像設備,還包含每個患者的唯一識別數據。如果 DICOM 文件能夠接收 DICOM 格式的圖像數據,則它們可以在兩方之間共享。 DICOM的通信部分是應用層協議,實體之間使用TCP/IP進行通信。 HTTP 和 HTTPS 協議用於 DICOM 的 Web 服務。 Web 服務支持的版本是 1.0、1.1、2 或更高版本。
閱讀更多其他支持的合併格式
使用 Java,可以輕鬆合併不同的格式,包括。