[vtkusers] What's wrong with my codes? (convert image to BMP)
vince xu
vince_xu at hotmail.com
Thu Mar 6 09:44:05 EST 2003
Could you look my simple codes?
I am so confused by that why these simple codes do not work.
How could I force vtkImagereader read data from files to memory?
In my program,when "output->CopyAndCastFrom( input,extent );" was executed,
it seems that "input" has no data at all.
#include "vtkimagewriter.h"
#include "vtkbmpwriter.h"
#include "vtkImageCast.h"
void main()
{
vtkImageReader *reader;
vtkBMPWriter *writer;
vtkImageData *input,*output;
int extent[6]={0,63,0,63,1,93};
char fname[100];
strcpy( fname,"Data/headsq/quarter" );
reader = vtkImageReader::New();
reader->SetDataByteOrderToBigEndian();
reader->SetDataExtent(extent);
reader->SetFilePrefix(fname);
reader->SetFilePattern("%s.%d");
reader->SetDataSpacing(3.2, 3.2, 1.5);
input = reader->GetOutput();
output = vtkImageData::New();
output->SetScalarTypeToUnsignedChar();
output->CopyAndCastFrom( input,extent );
strcpy( fname,"Data/headsq/bewrited" );
writer = vtkBMPWriter::New();
writer->SetFilePrefix(fname);
writer->SetFilePattern("%s.%d.BMP");
writer->SetInput(output);
writer->Write();
reader->Delete();
writer->Delete();
}
>From: "Zhang zhijun" <zjzhang at ee.cuhk.edu.hk>
>
>the headsq data are short format data, you cant' use the
>switch SetDataScalarTypeToUnsignedChar() to set these data,
>you can use a vtkImagecast to first change the data to
>a unsignedchar data then write it to a bmp file.
>
>regards,
>zhang zhijun
>vince_xu wrote:
> I want to convert the files
> quarter.1 --> quarter.1.bmp
> quarter.2 --> quarter.2.bmp
> quarter.3 --> quarter.3.bmp
> ......
> and so on.(files quarter.1 quarter.2......are available in
> VtkData\data\headsq which was unzipped from VTKDATA.zip)
>
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
More information about the vtkusers
mailing list