Java dicom查看_验证DICOM文件

我知道这已经得到了解答,但我有类似的要求,所以我掀起了一些扩展方法来做到这一点 . 适用于Files,FileStreams,MemoryStreams和通用Streams . 仅读取验证文件类型所需的特定4个字节 . 非常高效,我能够在几秒钟内完成数千个文件 .

C#

public static class Dicom

{

public static bool IsDicomFile(this Stream s)

{

//Create an empty 4 byte array

byte[] dba = new byte[4];

//Seek to 0x80

s.Seek(128, SeekOrigin.Begin);

//Read the following 4 dba

s.Read(dba, 0, 4);

//Compare to 'DICM'

return dba.SequenceEqual(new byte[4] {68, 73, 67, 77});

}

public static bool IsDicomFile(this MemoryStream ms)

{

return ((Stream)ms).IsDicomFile();

}

public static bool IsDicomFile(this FileStream fs)

{

return ((Stream)fs).IsDicomFile();

}

public static bool IsDicomFile(this FileInfo fi)

{

return fi.OpenRead().IsDicomFile();

}

}

VB.NET

_

Public Function IsDicomFile(ByVal s As Stream) As Boolean

'Create an empty 4 byte array

Dim dba() As Byte = New Byte(3) {}

'Seek to 0x80

s.Seek(128, SeekOrigin.Begin)

'Read the subsequent 4 bytes

s.Read(dba, 0, 4)

'Compare to 'DICM'

Return dba.SequenceEqual(New Byte(3) {68, 73, 67, 77})

End Function

_

Public Function IsDicomFile(ByVal ms As MemoryStream) As Boolean

Return DirectCast(ms, Stream).IsDicomFile

End Function

_

Public Function IsDicomFile(ByVal fs As FileStream) As Boolean

Return DirectCast(fs, Stream).IsDicomFile

End Function

_

Public Function IsDicomFile(ByVal fi As FileInfo) As Boolean

Return fi.OpenRead().IsDicomFile

End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值