private void jpeg2dicom(File archivoJPEG, File archivoDICOM) {
        try {
            BufferedImage jpegImage = ImageIO.read(archivoJPEG);
            if(jpegImage == null) {
                System.err.println("No se pudo crear imagen de archivo JPEG");
            }
            //atributos de imagen
            int colorComponents = jpegImage.getColorModel().getNumColorComponents();
            int bitsPerPixel = jpegImage.getColorModel().getPixelSize();
            int bitsAllocated = (bitsPerPixel / colorComponents);
            int samplesPerPixel = colorComponents;
            //crea un nuevo objeto dicom
            DicomObject dicom = new BasicDicomObject();
            dicom.putString(Tag.SpecificCharacterSet, VR.CS, "ISO_IR 100");
            dicom.putString(Tag.PhotometricInterpretation, VR.CS, samplesPerPixel == 3 ? "YBR_FULL_422" : "MONOCHROME2");
            dicom.putInt(Tag.SamplesPerPixel, VR.US, samplesPerPixel);       
            //valores del header obligatorios
            dicom.putInt(Tag.Rows, VR.US, jpegImage.getHeight());
            dicom.putInt(Tag.Columns, VR.US, jpegImage.getWidth());
            dicom.putInt(Tag.BitsAllocated, VR.US, bitsAllocated);
            dicom.putInt(Tag.BitsStored, VR.US, bitsAllocated);
            dicom.putInt(Tag.HighBit, VR.US, bitsAllocated-1);
            dicom.putInt(Tag.PixelRepresentation, VR.US, 0);
            dicom.putDate(Tag.InstanceCreationDate, VR.DA, new Date());
            dicom.putDate(Tag.InstanceCreationTime, VR.TM, new Date());
            //cada dicom debe tener un UID
            dicom.putString(Tag.StudyInstanceUID, VR.UI, UIDUtils.createUID());
            dicom.putString(Tag.SeriesInstanceUID, VR.UI, UIDUtils.createUID());
            dicom.putString(Tag.SOPInstanceUID, VR.UI, UIDUtils.createUID());
            //metafile information jpeg encapsulado en el dicom
            dicom.initFileMetaInformation(UID.JPEGBaseline1);
            //terminada la definicion de headers abre un outputstream al archivo dicom
            FileOutputStream fos = new FileOutputStream(archivoDICOM);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            DicomOutputStream dos = new DicomOutputStream(bos);
            dos.writeDicomFile(dicom);
            //configura los headers para la escritura de la imagen JPEG en el dicom
            dos.writeHeader(Tag.PixelData, VR.OB, -1);
            dos.writeHeader(Tag.Item, null, 0);
            /*
                According to Gunter from dcm4che team we have to take care that 
                the pixel data fragment length containing the JPEG stream has 
                an even length.
            */
            int jpgLen = (int) archivoJPEG.length(); 
            dos.writeHeader(Tag.Item, null, (jpgLen+1)&~1);
            FileInputStream fis = new FileInputStream(archivoJPEG);
            BufferedInputStream bis = new BufferedInputStream(fis);
            DataInputStream dis = new DataInputStream(bis);
            //escribe los datos del JPEG en el DICOM
            byte[] buffer = new byte[65536];       
            int b;
            while ((b = dis.read(buffer)) > 0) {
                dos.write(buffer, 0, b);
            }
            /*
                According to Gunter from dcm4che team we have to take care that 
                the pixel data fragment length containing the JPEG stream has 
                an even length. So if needed the line below pads JPEG stream with 
                odd length with 0 byte.
            */
            if ((jpgLen&1) != 0) dos.write(0); 
            dos.writeHeader(Tag.SequenceDelimitationItem, null, 0);
            dos.close();
        } catch (IOException ex) {
            System.err.println("Error al crar buffer en archivo JPEG");
        }
    }