title: Image replacement using PDFBox is showing garbled image
body: <p>I am using PDFBox 2.0.8 to replace image in pdf document. My process includes extract the image from document and write to file system. Compress the image which has been extracted. Compressed image needs to be replaced with the original image. However, after replacement PDF is showing garbled image. Refer page# 1 at the link 
  <a href="https://35.200.235.243/compression/download?fileName=/outbox/pdf/test123/test1-compress.pdf" rel="nofollow noreferrer">https://35.200.235.243/compression/download?fileName=/outbox/pdf/test123/test1-compress.pdf</a>. If i will open this document in Chrome then it seems to be better. However, on desktop it is garbled. In chrome the background color seems to have changed. However, there is no mask in this object</p>
  
  <pre><code>for (COSName xObjectName : resources.getXObjectNames()) {
                      PDXObject xObject = resources.getXObject(xObjectName);
                      if (xObject instanceof PDImageXObject) {
  
                          imageCounter++;
                          System.out.println("cosname="+xObjectName.toString());
                          PDImageXObject original_img = ((PDImageXObject) xObject);
                   String suffix = original_img.getSuffix();
                          File imageFile = new File(destPath+"/"+"image"+imageCounter+"."+suffix);
                          int imageWidth = original_img.getWidth();
                          int imageHeight = original_img.getHeight();
                          BufferedImage bImage = new BufferedImage(imageWidth,imageHeight,BufferedImage.TYPE_INT_RGB);
                          bImage = original_img.getOpaqueImage();
                          ImageIO.write(bImage,suffix, imageFile);
                  if(suffix.equalsIgnoreCase("jpg") || suffix.equalsIgnoreCase("jpeg")) {
  
                              System.out.println("found jpg="+imageFile.getAbsolutePath());
                              CompressPDFJPEG compress    =   new CompressPDFJPEG(imageFile.getAbsolutePath(), directoryID);
                              HashMap compressedFilesMap  =   compress.getCompressedFiles();
                              String compressedFiles []   =   (String[]) compressedFilesMap.get("compressedFiles");
                              String replaceImageFile     =   "";
                              for (int i=0;i&lt;compressedFiles.length;i++) {
  
                                  if (compressedFiles[i] != null) {
                                      replaceImageFile = compressedFiles[i];
                                  PDImageXObject replacement_img = PDImageXObject.createFromFile(replaceImageFile, doc);
                                  resources.put(xObjectName, replacement_img);
                                      doc.save(outFileName);
                                  break;
                                  }
  
                              }
                          }
  
                          if(suffix.equalsIgnoreCase("png")) {
  
                              CompressPDFPNG compress     =   new CompressPDFPNG(imageFile.getAbsolutePath(), directoryID);
                              HashMap compressedFilesMap  =   compress.compressPNG();
                              String compressedFiles []   =   (String[]) compressedFilesMap.get("compressedFiles");
                              String replaceImageFile     =   "";
                              for (int i=0;i&lt;compressedFiles.length;i++) {
  
                                  if (compressedFiles[i] != null) {
                                      replaceImageFile = compressedFiles[i];
                                      PDImageXObject replacement_img = PDImageXObject.createFromFile(replaceImageFile, doc);
                                          resources.put(xObjectName, replacement_img);
                                      break;
                                  }
  
                              }
  
  
                          }
  
  
                      }        
                  }
              }
  
       doc.close();
  </code></pre>
  
  <p>Here are the different links
  Original PDF:<strong><a href="https://35.200.235.243/compression/download?fileName=/inbox/pdf/test1.pdf" rel="nofollow noreferrer">https://35.200.235.243/compression/download?fileName=/inbox/pdf/test1.pdf</a></strong>
  Image Extracted     :   <strong><a href="https://35.200.235.243/compression/download?fileName=/work/pdf/test123/image2.jpg" rel="nofollow noreferrer">https://35.200.235.243/compression/download?fileName=/work/pdf/test123/image2.jpg</a></strong></p>
  
  <p>Compressed Image    :   <strong><a href="https://35.200.235.243/compression/download?fileName=/work/pdf/test123/image2-compress1.jpg" rel="nofollow noreferrer">https://35.200.235.243/compression/download?fileName=/work/pdf/test123/image2-compress1.jpg</a></strong>
  Compressed PDF      :   <strong><a href="https://35.200.235.243/compression/download?fileName=/outbox/pdf/test123/test1-compress.pdf" rel="nofollow noreferrer">https://35.200.235.243/compression/download?fileName=/outbox/pdf/test123/test1-compress.pdf</a></strong></p>
  
  <p>Desktop Screen Shot (Compressed PDF): </p>
  
  <p><a href="https://35.200.235.243/compression/download?fileName=/home/neelam_jain/Desktop_Screen_Shot.jpg" rel="nofollow noreferrer"><img src="https://35.200.235.243/compression/download?fileName=/home/neelam_jain/Desktop_Screen_Shot.jpg" alt=""></a></p>