[vtkusers] Is there any one know how to generate a JPEG filemanually?

Veerapuram Varadhan v.varadhan at californiadigital.com
Wed Mar 10 02:21:46 EST 2004


Qi,

Have a look at the following piece of code,

vtkJPEGWriter* jpegWriter = vtkJPEGWriter::New();
vtkWindowToImageFilter* winToImage = vtkWindowToImageFilter::New();
winToImage->SetInput (renderWindow);
winToImage->Update ();

jpegWriter->SetFileName ("/home/varadhan/mysnap.jpg");
jpegWriter->SetInput (winToImage->GetOutput());
jpegWriter->Write();

jpegWriter->Delete();
winToImage->Delete();

This code will save whatever image is rendered in the "renderwindow" as a
jpg file.

Otherwise,

As Mathieu suggested, you can use vtkImageShiftScale or vtkImageCast.

For example,

vtkImageShiftScale* shiftScale = vtkImageShiftScale::New();

shiftScale->SetInput (imageData->GetOutput());
shiftScale->SetOutputScalarTypeToUnsignedChar();
shiftScale->Update();

imageWriter->SetInput (shiftScale->GetOutput());

However, the above example requires a vtkImageData pointer.  In your code,
what is the type of "xy" that you have used in the loop?

Hope this helps...
V. Varadhan.

> Qi,
>
> Have a look at
> 	vtkImageShiftScale ::SetOutputScalarTypeToUnsignedChar ()
> or
> 	vtkImageCast::SetOutputScalarTypeToUnsignedChar ()
>
> HTH
> Mathieu
>
> Q Ma wrote:
>> Hi, there,
>>
>> Is there any one know how to generate a JPEG file manually?
>> I have an arrary of data, grey value for each pixel,and want to output
>> into a
>> JPEG file.
>> I use vtkJPEGWriter, with following code:
>>
>> vtkJPEGWriter *imagewriter=vtkJPEGWriter::New();
>>   imagewriter->SetFileName(imagefilename);
>> vtkStructuredPoints *im = vtkStructuredPoints::New();
>>   im->SetDimensions(1024,768,1);
>> vtkFloatArray *scalartemp = vtkFloatArray::New();
>> im->GetPointData()->SetScalars(scalartemp);
>> for(int x=0;x<1024;x++)
>> 	for(int y=0;y<768;y++)
>> 		scalartemp->InsertValue(y*1024+x,(char)(xy[x][y][2]/5));
>> imagewriter->SetInput(im);
>> imagewriter->Write();
>>
>> It does not work. And an error reported like this:
>> warning: In /var/tmp/BUILD-cedward1/VTK/IO/vtkJPEGWriter.cxx, line 186
>> vtkJPEGWriter only supports unsigned char input
>>
>> Can anyone with some help on how to output JPEG file manually?
>> Thank you very much.
>>
>> Regards,
>> Qi
>>
>>
>> _______________________________________________
>> This is the private VTK discussion list.
>> Please keep messages on-topic. Check the FAQ at:
>> <http://public.kitware.com/cgi-bin/vtkfaq>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>




More information about the vtkusers mailing list