0

Trying to replace:

ORDSYS.ORDIMAGE.PROCESSCOPY(P_BLOB, 'maxScale=100 100', V_DST);

Seemed to be working last week, now I'm getting the error "Exception in thread "Root Thread" java.lang.nullPointerException: Could not initialize inverse tables".

Can't find much information on the error anywhere.

The error occurs here:

imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0,0,0), null);

Oracle Functions:

function BLOB_THUMBNAIL(P_BLOB in Blob, P_MAX_SIZE in Number, P_ATTACH_SID in varchar2 := null) return Blob is

        V_DST              Blob;

    begin

        V_DST := resizeBLOB(P_BLOB, P_MAX_SIZE, P_MAX_SIZE);

    end BLOB_THUMBNAIL;

    function BLOB_THUMBNAIL_OLD(P_BLOB in Blob, P_MAX_SIZE in Number) return Blob is

        V_DST   Blob;

    begin
        DBMS_LOB.CREATETEMPORARY(V_DST, true);

        DBMS_LOB.OPEN(V_DST, DBMS_LOB.LOB_READWRITE);

        ORDSYS.ORDIMAGE.PROCESSCOPY(P_BLOB, 'maxScale=' || P_MAX_SIZE || ' ' || P_MAX_SIZE, V_DST);

        DBMS_LOB.CLOSE(V_DST);

        return V_DST;

end BLOB_THUMBNAIL_OLD;


Java Class:
SET DEFINE OFF;
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "ResizeImage" as 
import java.lang.*;
import java.sql.*;
import java.io.*;
import oracle.sql.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.awt.Color;
import javax.imageio.ImageIO;
import oracle.jdbc.driver.*;

public class ResizeImage extends Object
{
 public static java.sql.Blob resizeBLOB(java.sql.Blob img, int newW, int newH)
 {
  try
     {
      byte [] newdata = img.getBytes(1L, (int)img.length());
      newdata = scale(newdata, newW, newH);

      oracle.jdbc.OracleConnection conn = (oracle.jdbc.OracleConnection)new OracleDriver().defaultConnection();
      java.sql.Blob retBlob = conn.createBlob();

      try
         {
          java.io.OutputStream outStr = retBlob.setBinaryStream(0);
          outStr.write(newdata, 0, newdata.length);
          outStr.flush();
          outStr.close();
         }
      catch (IOException ioe)
           {
            System.out.println("IO Error trying to write the outputstream.");  
            ioe.printStackTrace();
           } 
           
      return retBlob;
     }
  catch (SQLException ex)
       {
        System.out.println("SQLException Error.");  
        ex.printStackTrace();
       }  

  return img;
 }

 public static byte[] scale(byte[] fileData, int width, int height) 
 {
  double newW;
  double newH;
 
  ByteArrayInputStream in = new ByteArrayInputStream(fileData);
  try 
     {
      BufferedImage img = ImageIO.read(in);

      if(height == 0) 
        height = 100; 

      if(width == 0)
        width = 100;

      //Figure new Width and Height with Aspect Ratio
      double imgW = img.getWidth();
      double imgH = img.getHeight();

      if(imgH>imgW)
        {
         newW = (imgW/imgH)*width;
         newH = height;
        }
      else
        {
         newH = (imgH/imgW)*height;
         newW = width;
        }

      Image scaledImage = img.getScaledInstance((int)newW, (int)newH, Image.SCALE_SMOOTH);
      BufferedImage imageBuff = new BufferedImage((int)newW, (int)newH, BufferedImage.TYPE_INT_RGB);
      imageBuff.getGraphics().drawImage(scaledImage, 0, 0, new Color(0,0,0), null);

      ByteArrayOutputStream buffer = new ByteArrayOutputStream();

      ImageIO.write(imageBuff, "jpg", buffer);
      return buffer.toByteArray();
     } 
   catch (IOException e)
        {
         //throw new ApplicationException("IOException in scale");
         e.printStackTrace();       
        }
  return fileData;
 }
}

Oracle Function to call Java:
CREATE OR REPLACE function resizeBLOB( p_img in blob, newW in number, newH in number) return blob
as
language java
name 'ResizeImage.resizeBLOB(java.sql.Blob, int, int) return java.sql.Blob';
/


Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
  • 1
    "Ordimage has been removed from 19c (I know you are using 12c)" <- Excuse me but who are you talking to? – OH GOD SPIDERS Mar 22 '21 at 13:11
  • And what does the title have to do with the main text? If you have a problem that you found a potentially useful solution, you should post it as a self-answered question - still with a clear question detailing the problem, and a separate complete answer. – Alex Poole Mar 22 '21 at 13:45
  • Ah... so you're asking a follow-on [from your earlier answer](https://stackoverflow.com/a/66709714/266304)? It you're getting the NPE then make *this* question a self-contained [mcve] - not just a copy of that answer with no context and nothing about the new error you're getting. – Alex Poole Mar 22 '21 at 13:47
  • I posted this as a comment to another question to try to help someone else but now this all stopped working somehow. The server was rebooted over the weekend so that may have something to do with it. I just can't find any information on the error. I'll fix the above so it's less confusing. – Timothy Ward Mar 22 '21 at 13:57
  • This is the exact code that was working last week, no changes except the server was rebooted and now I'm getting the error. – Timothy Ward Mar 22 '21 at 14:00
  • Does the full error help at all? – Timothy Ward Mar 22 '21 at 14:40
  • Exception in thread "Root Thread" java.lang.NullPointerException: Could not initialize inverse tables at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java) at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java) at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java) at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java) at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java) – Timothy Ward Mar 22 '21 at 14:40
  • at sun.awt.image.ImageRepresentation.drawToBufImage(ImageRepresentation.java) at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java) at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java) at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java) at ResizeImage.scale(ResizeImage:157) at ResizeImage.resizeBLOB(ResizeImage:21) – Timothy Ward Mar 22 '21 at 14:40
  • I rebooted the Oracle Server and now I'm not getting the error, now I'm just getting half of the original image, the other half is just black. This is really weird. – Timothy Ward Mar 22 '21 at 15:51

0 Answers0