WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
string str = @"D:\VM\7172bd16-a097-4a6c-bb52-ebac34a608aa.dcm";
RasterImage srcImage = null;
IDataCacheProvider dataCache = new DiskDataCacheProvider(new DiskDataCacheStorage(@"C:\Cache"));
if (!string.IsNullOrEmpty(str))
{
using (var dicomSourceProxy = new DicomSourceProxy(dataCache))
{
var query = new ViewImageQuery() { FileName = str, FrameNumber = 1, Rasterize = true };
try
{
srcImage = dicomSourceProxy.Load(query).Image;
}
catch
{
//ignored
}
}
}
MemoryStream imageStream = new MemoryStream();
RasterCodecs codecs = new RasterCodecs();
codecs.Options.Jpeg.Save.QualityFactor = 2;
codecs.Options.Jpeg.Save.Passes = -1;
codecs.Save(srcImage, imageStream, RasterImageFormat.Jpeg, 8);
return imageStream;
用WCF服务发布接口出去,用接口服务接收流 就能看到图片
string str = @"D:\VM\7172bd16-a097-4a6c-bb52-ebac34a608aa.dcm";
string destFileName = @"D:\VM\E.jpg";
RasterImage srcImage = null;
IDataCacheProvider dataCache = new DiskDataCacheProvider(new DiskDataCacheStorage(@"C:\Cache"));
if (!string.IsNullOrEmpty(str))
{
using (var dicomSourceProxy = new DicomSourceProxy(dataCache))
{
var query = new ViewImageQuery() { FileName = str, FrameNumber = 1, Rasterize = true };
try
{
srcImage = dicomSourceProxy.Load(query).Image;
}
catch
{
//ignored
}
}
}
RasterCodecs codecs = new RasterCodecs();
codecs.Options.Jpeg.Save.QualityFactor = 2;
codecs.Options.Jpeg.Save.Passes = -1;
codecs.Save(srcImage, destFileName , RasterImageFormat.Jpeg, 8);
但是我以文件的形式保存到本地这个Jpeg的格式图片就看不了
同样本地保存文件PNG或者其它格式都能看到
用这个保存RasterImageFormat.Png参数设置png你就能看到本地文件图片了
codecs.Save(srcImage, destFileName, RasterImageFormat.Png, 0);
换了好多dicom都是这个情况 |