Exemplo n.º 1
0
    public static bool ProcessOneFile(string filename, string outfilename)
    {
        PixmapReader reader = new PixmapReader();

        reader.SetFileName(filename);
        if (!reader.Read())
        {
            System.Console.WriteLine("Could not read: " + filename);
            return(false);
        }

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();

        change.SetForce(false);             // do we really want to recompress when input is alread compressed in same alg ?
        change.SetCompressIconImage(false); // Keep it simple
        change.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEG2000Lossless));
        change.SetInput(reader.GetPixmap());
        if (!change.Change())
        {
            System.Console.WriteLine("Could not change: " + filename);
            return(false);
        }

        gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove(new gdcm.Tag(0x0002, 0x0012));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0013));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0016));

        PixmapWriter writer = new PixmapWriter();

        writer.SetFileName(outfilename);
        writer.SetFile(reader.GetFile());
        gdcm.Bitmap bitout = change.GetOutput();
        gdcm.Pixmap pixout = (gdcm.Pixmap)bitout;
        //System.Console.WriteLine( "Debug: " + pixout.toString() );

        writer.SetPixmap(pixout);
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(false);
        }

        return(true);
    }
Exemplo n.º 2
0
    public static bool ProcessOneFile( string filename, string outfilename )
    {
        PixmapReader reader = new PixmapReader();
        reader.SetFileName( filename );
        if( !reader.Read() )
          {
          System.Console.WriteLine( "Could not read: " + filename );
          return false;
          }

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
        change.SetForce( false ); // do we really want to recompress when input is alread compressed in same alg ?
        change.SetCompressIconImage( false ); // Keep it simple
        change.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.JPEG2000Lossless ) );
        change.SetInput( reader.GetPixmap() );
        if( !change.Change() )
          {
          System.Console.WriteLine( "Could not change: " + filename );
          return false;
          }

        gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove( new gdcm.Tag(0x0002,0x0012) );
        fmi.Remove( new gdcm.Tag(0x0002,0x0013) );
        fmi.Remove( new gdcm.Tag(0x0002,0x0016) );

        PixmapWriter writer = new PixmapWriter();
        writer.SetFileName( outfilename );
        writer.SetFile( reader.GetFile() );
        gdcm.Bitmap bitout = change.GetOutput();
        gdcm.Pixmap pixout = (gdcm.Pixmap)bitout;
        //System.Console.WriteLine( "Debug: " + pixout.toString() );

        writer.SetPixmap( pixout );
        if( !writer.Write() )
          {
          System.Console.WriteLine( "Could not write: " + outfilename );
          return false;
          }

        return true;
    }