我用VC写了一个DICOM图象打印程序,CT图象能正常打印,MR、CR也能正常打印,但是在打印DR时出错,打印的胶片打反了,胶片上无法正常看。
打印处理见代码,希望各位同仁帮忙看下,问题出在哪里,谢谢
void CDicomPrint::OnPrint()
{
m_Empty.EnableWindow( FALSE );
m_Print.EnableWindow( FALSE );
m_OK.EnableWindow( FALSE );
long lHeight = 512;
long lWidth = 512;
DWORD dwBitsLen = 0;
long lNumPrint = m_iX * m_iY;
long lPos = 0;
char szFilmSize[0xff];
char szImageDispFormat[0xff];
char szPages[0xff];
long lPages = 0;
char *tmp;
sprintf( szFilmSize, "%dINX%dIN", (long)m_dFilmX, (long)m_dFilmY );
sprintf( szImageDispFormat, "STANDARD\\%d,%d", m_iX, m_iY );
lPages = strtod( m_Pages_Value, &tmp );
if( lPages < 1 )
{
lPages = 1;
}
sprintf( szPages, "%d", lPages );
DicomServer_Struct *DicomServer = new DicomServer_Struct;
DicomServer->strSopClass = UID_BASIC_GRAY_PRINT_MGMT_META_SOP_CLASS;
DicomServer->strIp = m_strIP;
DicomServer->strPort = m_strPort;
DicomServer->called_AE = m_strAETitle;
DicomServer->calling_AE = m_strCallingAETitle;
DicomServer->Print = new Print_Struct();
DicomServer->Print->dwNCREATERQ_2_SEQ_Tag = TAG_REFFILMSESSIONSEQUENCE;
DicomServer->Print->dwNSETRQ_SEQ_Tag = TAG_BASICGRAYSCALEIMAGESEQ;
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_1, TAG_NUMBER_OF_COPIES, VR_IS, strlen( szPages ), szPages );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_1, TAG_PRINT_PRIORITY, VR_CS, m_strPriority.GetLength(), m_strPriority.GetBuffer( m_strPriority.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_1, TAG_MEDIUM_TYPE, VR_CS, m_strMedium_type.GetLength(), m_strMedium_type.GetBuffer( m_strMedium_type.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_1, TAG_FILM_DESTINATION, VR_CS, m_strDestination.GetLength(), m_strDestination.GetBuffer( m_strDestination.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_IMAGE_DISPLAY_FORMAT, VR_ST, m_strImage_display_format.GetLength(), m_strImage_display_format.GetBuffer( m_strImage_display_format.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_FILM_ORIENTATION, VR_CS, m_strOrientation.GetLength(), m_strOrientation.GetBuffer( m_strOrientation.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_FILM_SIZE_ID, VR_CS, strlen( szFilmSize ), szFilmSize );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_MAGNIFICATION_TYPE, VR_CS, m_strMagnification_type.GetLength(), m_strMagnification_type.GetBuffer( m_strMagnification_type.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_BORDER_DENSITY, VR_CS, m_strBorder_density.GetLength(), m_strBorder_density.GetBuffer( m_strBorder_density.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_EMPTY_IMAGE_DENSITY, VR_CS, m_strImage_density.GetLength(), m_strImage_density.GetBuffer( m_strImage_density.GetLength() ) );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_MIN_DENSITY, VR_US, 0, "", 1, 0x000A );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_MAX_DENSITY, VR_US, 0, "", 1, 0x015E );
DicomServer->Print->InsertElem( &DicomServer->Print->NCREATERQ_2, TAG_TRIM, VR_CS, 2, "NO" );
while( BSDicomViewPrint && lNumPrint -- > 0 )
{
DicomServer->Print->InsertElem( TRUE, FALSE, TAG_MAGNIFICATION_TYPE, VR_ST, 9, "REPLICATE" );
DicomServer->Print->InsertElem( FALSE, FALSE, TAG_IMAGE_POS, VR_US, 0, "", 1, ++lPos );
DicomServer->Print->InsertElem( FALSE, FALSE, TAG_POLARITY, VR_CS, m_strPolarity.GetLength(), m_strPolarity.GetBuffer( m_strPolarity.GetLength() ) );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_SAMPLES_PER_PX, VR_US, 0, "", 1, 1 );
if( BSDicomViewPrint->BSDicomView->GetImageType() == 1 )
{
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PHOTOMETRIC, VR_CS, 11, "MONOCHROME1" );
}
else if( BSDicomViewPrint->BSDicomView->GetImageType() == 2 )
{
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PHOTOMETRIC, VR_CS, 11, "MONOCHROME2" );
}
else// if( !BSDicomView->BSDicomView->IsLoad() )
{
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PHOTOMETRIC, VR_CS, 11, "MONOCHROME2" );
if( lHeight == 0 || lWidth == 0 )
{
lHeight = 512;
lWidth = 512;
}
dwBitsLen = ( lWidth + 3 ) / 4 * 4 * lHeight;
char *bufferTemp = new char[ dwBitsLen + 1 ];
for( long iBuffer = 0; iBuffer < dwBitsLen + 1; iBuffer ++ )
{
// bufferTemp[ iBuffer ] = ( iBuffer % ( ( lWidth + 3 ) / 4 * 4 ) ) % 0x100;
bufferTemp[ iBuffer ] = 0;
}
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_COLUMNS, VR_US, 0, "", 1, ( lWidth + 3 ) / 4 * 4 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_ROWS, VR_US, 0, "", 1, lHeight );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_BITS_ALLOC, VR_US, 0, "", 1, 8 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_BITS_STORED, VR_US, 0, "", 1, 8 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_HIGH_BIT, VR_US, 0, "", 1, 7 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PX_REPRESENT, VR_US, 0, "", 1, 0x0000 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PIXEL_DATA, VR_OB, dwBitsLen, bufferTemp );
BSDicomViewPrint = BSDicomViewPrint->Next;
delete bufferTemp;
continue;
}
lHeight = BSDicomViewPrint->BSDicomView->GetImageWidth();
lWidth = BSDicomViewPrint->BSDicomView->GetImageHeight();
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_COLUMNS, VR_US, 0, "", 1, ( BSDicomViewPrint->BSDicomView->GetImageWidth() + 3 ) / 4 * 4 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_ROWS, VR_US, 0, "", 1, BSDicomViewPrint->BSDicomView->GetImageHeight() );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_BITS_ALLOC, VR_US, 0, "", 1, 8 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_BITS_STORED, VR_US, 0, "", 1, 8 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_HIGH_BIT, VR_US, 0, "", 1, 7 );
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PX_REPRESENT, VR_US, 0, "", 1, 0x0000 );
dwBitsLen = ( BSDicomViewPrint->BSDicomView->GetImageWidth() + 3 ) / 4 * 4 * BSDicomViewPrint->BSDicomView->GetImageHeight();
DicomServer->Print->InsertElem( FALSE, TRUE, TAG_PIXEL_DATA, VR_OB, dwBitsLen, (char*)BSDicomViewPrint->BSDicomView->GetOutputData() );
BSDicomViewPrint = BSDicomViewPrint->Next;
}
if( Progress )
{
Progress->ShowWindow( SW_SHOW );
Progress->m_progress.SetRange( 0, 1 );
Progress->m_progress.SetPos( 0 );
}
if( m_print_server.Connect((long)DicomServer) == 0 )
{
char szTemp[0xff];
sprintf( szTemp,"发送打印页失败");
MessageBox(szTemp);
BSDicomViewPrint = NULL;
}
if( DicomServer )
{
delete DicomServer;
DicomServer = NULL;
}
if( BSDicomViewPrint == NULL )
{
m_Empty.EnableWindow( TRUE );
m_Print.EnableWindow( TRUE );
m_OK.EnableWindow( TRUE );
m_strPriority.ReleaseBuffer();
m_strMedium_type.ReleaseBuffer();
m_strDestination.ReleaseBuffer();
m_strImage_display_format.ReleaseBuffer();
m_strOrientation.ReleaseBuffer();
m_strMagnification_type.ReleaseBuffer();
m_strBorder_density.ReleaseBuffer();
m_strImage_density.ReleaseBuffer();
m_strPolarity.ReleaseBuffer();
}
}
本文来源:http://go-health.cn/bbs//viewthread.php?tid=11106&extra=&ordertype=1