void* data |
Pointer to pixel image data. |
long bytesToWrite |
The number of bytes to write from the image data. |
long fPixl |
[ optional ] The start pixel within the FITS file image. If
left blank, then the next write position will be this->fPixel plus bytesToWrite. If fPixel >= 0,
then data will be written there. |
// This code demonstrates how to write a 1024x1200
// pixel FITS file filled with a gradient.
#include <iostream>
#include "CFitsFile.h"
using namespace std;
using namespace arc;
int main()
{
unsigned short *pBuf = NULL;
unsigned short val = 0;
try {
CFitsFile cFits( "Image.fit", 1024, 1200 );
//
// Create new image data
//
pBuf = new unsigned short[ 1024 * 1200 ];
if ( pBuf == NULL )
{
cerr << "Error: NULL image buffer!" << endl;
exit( 1 );
}
//
// Fill the new buffer with a gradient image
//
for ( int r=0; r<1024; r++ )
{
for ( int c=0; c<1200; c++ )
{
pBuf[ c + r * 1200 ] = val;
}
if ( val >= 65535 ) val = 0;
else val++;
}
//
// Write the image data
//
cFits.Write( pBuf );
delete[] pBuf;
}
catch ( std::exception &e )
{
cerr << "Exception Occurred: " << e.what() << endl;
if ( pBuf != NULL ) delete[] pBuf;
}
}
// This code demonstrates how to write a 200x300 sub-image
// from a 1024x1200 pixel image into the FITS file at the
// start location of ( 0, 0 ).
#include <iostream>
#include "CFitsFile.h"
using namespace std;
using namespace arc;
int main()
{
unsigned short *pBuf = NULL;
unsigned short val = 0;
try {
CFitsFile cFits( "Image.fit", 1024, 1200 );
//
// Create new image data
//
pBuf = new unsigned short[ 1024 * 1200 ];
if ( pBuf == NULL )
{
cerr << "Error: NULL image buffer!" << endl;
exit( 1 );
}
//
// Fill the new buffer with a gradient image
//
for ( int r=0; r<1024; r++ )
{
for ( int c=0; c<1200; c++ )
{
pBuf[ c + r * 1200 ] = val;
}
if ( val >= 65535 ) val = 0;
else val++;
}
//
// Write the image data
//
cFits.Write( pBuf, ( 200 * 300 * sizeof( unsigned short ) ), 0 );
delete[] pBuf;
}
catch ( std::exception &e )
{
cerr << "Exception Occurred: " << e.what() << endl;
if ( pBuf != NULL ) delete[] pBuf;
}
}
© Astronomical Research Cameras, Inc.