public bool OpenPXEImageFromMemory(MemoryStream pxeFile) { byte[] pxeData = new byte[pxeFile.Length]; using (BinaryReader r = new BinaryReader(pxeFile)) { // Read data from Test.data. pxeData = r.ReadBytes((int)pxeFile.Length); } buffersAvailable.Clear(); pxeHeader = OpenAndProcessPXEImageFromMemory(pxeData, (int)pxeData.Length); if (pxeHeader.isValidFile != 1) { ClearActiveBagBuffer(); return(false); } LoadPXEData(); ClearActiveBagBuffer(); CloseActiveBag(); pxeFile.Close(); pxeFile.Dispose(); return(true); }
public bool OpenPXEFile(string BagName) { PXEHeader pxeHeader = OpenPXEImage(BagName); if (pxeHeader.bValidFile != 1) { return(false); } return(true); }
public BitmapSource RawPXEDataIn32Bits(string BagName) { PXEHeader pxeHeader = OpenPXEImage(BagName); string engbufname = "RawH"; int height = GetPXEHeight(engbufname); if (height < 1) { engbufname = "RawL"; height = GetPXEHeight(engbufname); } int width = GetPXEWidth(engbufname); if (height * width > 0) { m_32BitFloatNormData = new float[height * width]; bool bRet = GetPXEData(engbufname, m_32BitFloatNormData); float[] rawDataCopy = new float[height * width]; m_32BitFloatNormData.CopyTo(rawDataCopy, 0); for (int j1 = 0; j1 < height; j1++) { for (int i1 = 0; i1 < width; i1++) { m_32BitFloatNormData[(j1 * width) + i1] = rawDataCopy[(i1 * height) + j1]; } } for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { m_32BitFloatNormData[(j * width) + i] = m_32BitFloatNormData[(j * width) + i] / 65536; } } PixelFormat pf = PixelFormats.Gray32Float; int rawStride = (width * pf.BitsPerPixel + 7) / 8; BitmapSource bitmapImg = BitmapSource.Create(width, height, 96, 96, pf, null, m_32BitFloatNormData, rawStride); ClosePXEImage(); return(bitmapImg); } else { return(null); } }
public bool OpenPXEFile(string BagName) { PXEHeader pxeHeader = OpenPXEImage(BagName); if (pxeHeader.bValidFile != 1) { return(false); } if (pxeHeader.EngeryBuffers == 0) { return(true); } string engbufname = "RawH"; int height = GetPXEHeight(engbufname); m_Img_Ht = height; if (height < 1) { engbufname = "RawL"; height = GetPXEHeight(engbufname); m_Img_Ht = height; } int width = GetPXEWidth(engbufname); m_Img_Width = width; if (height * width > 0) { m_32BitFloatNormData = new float[height * width]; m_rawData = new float[height * width]; bool bRet = GetPXEData(engbufname, m_rawData);//m_32BitFloatNormData); //Adjust col to row form for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { m_32BitFloatNormData[(j * width) + i] = m_rawData[(i * height) + j] / 65536; } } ClosePXEImage(); return(true); } else { return(false); } }
//============================================================== public float[] ReadLine(string BagName, ref bool res) { float[] linedata = new float[0]; PXEHeader pxeHeader = OpenPXEImage(BagName); if (pxeHeader.bValidFile != 1) { res = false; return(linedata); } string engbufname = "LinearReferenceH"; int height = GetPXEHeight(engbufname); m_Img_Ht = height; if (height < 1) { engbufname = "RawL"; height = GetPXEHeight(engbufname); m_Img_Ht = height; } int width = GetPXEWidth(engbufname); m_Img_Width = width; if (height * width > 0) { m_rawData = new float[height * width]; bool bRet = GetPXEData(engbufname, m_rawData); ClosePXEImage(); res = true; return(m_rawData); } else { res = false; return(linedata); } }
public bool OpenPXEImageFromMemoryWithTIP(MemoryStream pxeFile, MemoryStream tipPXEFile, ref TIPStatus tipStatus) { byte[] pxeData = new byte[pxeFile.Length]; using (BinaryReader r = new BinaryReader(pxeFile)) { // Read data from Test.data. pxeData = r.ReadBytes((int)pxeFile.Length); } buffersAvailable.Clear(); byte[] tipPXEData = new byte[tipPXEFile.Length]; using (BinaryReader r = new BinaryReader(tipPXEFile)) { // Read data from Test.data. tipPXEData = r.ReadBytes((int)tipPXEFile.Length); } buffersAvailable.Clear(); pxeHeader = OpenAndProcessPXEImageFromMemoryWithTIP(pxeData, (int)pxeData.Length, tipPXEData, (int)tipPXEData.Length, ref tipStatus); if (pxeHeader.isValidFile != 1) { ClearActiveBagBuffer(); return false; } LoadPXEData(); ClearActiveBagBuffer(); CloseActiveBag(); tipPXEFile.Close(); tipPXEFile.Dispose(); pxeFile.Close(); pxeFile.Dispose(); return true; }
public bool CreateJPEGFromFile(FileInfo pxeFile) { bool Ret = false; try { using (FileStream fs = new FileStream(pxeFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { byte[] pxeData = new byte[pxeFile.Length]; using (BinaryReader r = new BinaryReader(fs)) { // Read data from Test.data. pxeData = r.ReadBytes((int)pxeFile.Length); } pxeHeader = OpenPXEImageFromMemory(pxeData, (int)pxeData.Length); if (pxeHeader.isValidFile != 1) { ClearActiveBagBuffer(); return(false); } ImageBufferIndices ibi = ImageBufferIndices.Unknown; ImageViewIndices ivi = ImageViewIndices.Unknown; int width = 0; int height = 0; if (pxeHeader.viewBuffer_0.isValidView != 0) { if (pxeHeader.viewBuffer_0.isDualEnergy != 0 || pxeHeader.viewBuffer_0.isHighEnergy != 0) { ibi = ImageBufferIndices.RawH; } else { ibi = ImageBufferIndices.RawL; } width = Convert.ToInt32(pxeHeader.viewBuffer_0.width); height = Convert.ToInt32(pxeHeader.viewBuffer_0.height); m_rawData = new float[pxeHeader.viewBuffer_0.height * pxeHeader.viewBuffer_0.width]; ivi = ImageViewIndices.View1; } else if (pxeHeader.viewBuffer_1.isValidView != 0) { if (pxeHeader.viewBuffer_1.isDualEnergy != 0 || pxeHeader.viewBuffer_1.isHighEnergy != 0) { ibi = ImageBufferIndices.RawH1; } else { ibi = ImageBufferIndices.RawL1; } width = Convert.ToInt32(pxeHeader.viewBuffer_1.width); height = Convert.ToInt32(pxeHeader.viewBuffer_1.height); m_rawData = new float[pxeHeader.viewBuffer_1.height * pxeHeader.viewBuffer_1.width]; ivi = ImageViewIndices.View2; } if (ibi != ImageBufferIndices.Unknown && ivi != ImageViewIndices.Unknown) { GetDataBuffer(Convert.ToUInt32(ibi), (int)ivi, m_rawData, true); PixelFormat pf = PixelFormats.Gray32Float; int rawStride = (width * pf.BitsPerPixel + 7) / 8; BitmapSource Source = BitmapSource.Create(width, height, 96.0, 96.0, pf, null, m_rawData, rawStride); int maxWidth = 150; int maxHeight = 100; double ratio = (width > height) ? (double)maxWidth / (double)width : (double)maxHeight / (double)height; using (FileStream stream = new FileStream(Path.Combine(pxeFile.DirectoryName, "Thumb.jpg"), FileMode.Create)) { JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.QualityLevel = 100; TransformedBitmap thumbnail = new TransformedBitmap(Source, new ScaleTransform(ratio, ratio)); encoder.Frames.Add(BitmapFrame.Create(thumbnail)); encoder.Save(stream); } } ClearActiveBagBuffer(); CloseActiveBag(); } } catch { //DLL may not exist } return(Ret); }
public bool CreateJPEGFromFile(FileInfo pxeFile) { bool Ret = false; try { using (FileStream fs = new FileStream(pxeFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { byte[] pxeData = new byte[pxeFile.Length]; using (BinaryReader r = new BinaryReader(fs)) { // Read data from Test.data. pxeData = r.ReadBytes((int)pxeFile.Length); } pxeHeader = OpenPXEImageFromMemory(pxeData, (int)pxeData.Length); if (pxeHeader.isValidFile != 1) { ClearActiveBagBuffer(); return false; } ImageBufferIndices ibi = ImageBufferIndices.Unknown; ImageViewIndices ivi = ImageViewIndices.Unknown; int width = 0; int height = 0; if (pxeHeader.viewBuffer_0.isValidView != 0) { if (pxeHeader.viewBuffer_0.isDualEnergy != 0 || pxeHeader.viewBuffer_0.isHighEnergy != 0) { ibi = ImageBufferIndices.RawH; } else { ibi = ImageBufferIndices.RawL; } width = Convert.ToInt32(pxeHeader.viewBuffer_0.width); height = Convert.ToInt32(pxeHeader.viewBuffer_0.height); m_rawData = new float[pxeHeader.viewBuffer_0.height * pxeHeader.viewBuffer_0.width]; ivi = ImageViewIndices.View1; } else if (pxeHeader.viewBuffer_1.isValidView != 0) { if (pxeHeader.viewBuffer_1.isDualEnergy != 0 || pxeHeader.viewBuffer_1.isHighEnergy != 0) { ibi = ImageBufferIndices.RawH1; } else { ibi = ImageBufferIndices.RawL1; } width = Convert.ToInt32(pxeHeader.viewBuffer_1.width); height = Convert.ToInt32(pxeHeader.viewBuffer_1.height); m_rawData = new float[pxeHeader.viewBuffer_1.height * pxeHeader.viewBuffer_1.width]; ivi = ImageViewIndices.View2; } if (ibi != ImageBufferIndices.Unknown && ivi != ImageViewIndices.Unknown) { GetDataBuffer(Convert.ToUInt32(ibi), (int)ivi, m_rawData, true); PixelFormat pf = PixelFormats.Gray32Float; int rawStride = (width * pf.BitsPerPixel + 7) / 8; BitmapSource Source = BitmapSource.Create(width, height, 96.0, 96.0, pf, null, m_rawData, rawStride); int maxWidth = 150; int maxHeight = 100; double ratio = (width > height) ? (double)maxWidth / (double)width : (double)maxHeight / (double)height; using (FileStream stream = new FileStream(Path.Combine(pxeFile.DirectoryName, "Thumb.jpg"), FileMode.Create)) { JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.QualityLevel = 100; TransformedBitmap thumbnail = new TransformedBitmap(Source, new ScaleTransform(ratio, ratio)); encoder.Frames.Add(BitmapFrame.Create(thumbnail)); encoder.Save(stream); } } ClearActiveBagBuffer(); CloseActiveBag(); } } catch { //DLL may not exist } return Ret; }