Reading from blob images!

Hi! I have servlet:
package kokaugi.view.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;
import oracle.jbo.client.Configuration;
import oracle.jbo.domain.BlobDomain;
public class ImageServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                                             throws ServletException, IOException {
         processResponse(req,res);
     public void doPost(HttpServletRequest req, HttpServletResponse res)
                                             throws ServletException, IOException {
         processResponse(req,res);
     private void processResponse(HttpServletRequest req, HttpServletResponse res)
                                             throws ServletException, IOException{
         String imageId = req.getParameter("Id");
         OutputStream out = res.getOutputStream();
         String amDef = "kokaugi.model.KokaugiModule";
         String config = "KokaugiModuleLocal";
         ApplicationModule am =  Configuration.createRootApplicationModule(amDef, config);
         ViewObject vo = am.findViewObject("ADokumentiDati1");
         if(imageId != null){
           vo.setWhereClause("A_DOKUMENTI_PK=:img_id_tab");
                      vo.defineNamedWhereClauseParam("img_id_tab", null, null);
                      vo.setNamedWhereClauseParam("img_id_tab", imageId);
                      String query = vo.getQuery();
                      System.out.println(query);
                      vo.executeQuery();
         if(vo.getEstimatedRowCount()==1){
            Row currentRow = vo.first();
            String contentType = (String)currentRow.getAttribute("DokumentaTips");
            if(contentType.equals("image/jpeg") || contentType.equals("image/gif")|| contentType.equals("image/png")){
                    BlobDomain image = (BlobDomain)currentRow.getAttribute("Dokuments");
                    res.setContentType(contentType);
                            InputStream is = image.getInputStream();
                            byte[] buffer = new byte[10 * 1024];
                            int nread;
                            while ((nread = is.read(buffer)) != -1)
                            out.write(buffer, 0, nread);
                            out.flush();
                            out.close();
        Configuration.releaseRootApplicationModule(am, false);
}Then in page I can see images using: /ImageServlet?Id=#{bindings.ADokumentiPk.inputValue}Viewing images in some records I can see them but in some not! Where might be problem? If You need more info, please let me know it!
best regards, Debuger!

Hi, Timo! For the Jspx page I use popup when preset with right click on table record:
<af:popup id="imagePopup" contentDelivery="lazyUncached">
                    <af:dialog id="d2" type="ok"
                               title="#{sampleBundle.apskate}">
                      <af:panelGroupLayout id="pgl1" layout="scroll"
                                           inlineStyle="width:550px; height:450.0px;">
                        <af:image source="/ImageServlet?Id=#{bindings.ADokumentiPk.inputValue}"
                                  id="i1" shortDesc="#{sampleBundle.apskate}"/>
                      </af:panelGroupLayout>
                    </af:dialog>
                  </af:popup>And there are image that uses servlet:
package kokaugi.view.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oracle.jbo.ApplicationModule;
import oracle.jbo.Row;
import oracle.jbo.ViewObject;
import oracle.jbo.client.Configuration;
import oracle.jbo.domain.BlobDomain;
public class ImageServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                                             throws ServletException, IOException {
         processResponse(req,res);
     public void doPost(HttpServletRequest req, HttpServletResponse res)
                                             throws ServletException, IOException {
         processResponse(req,res);
       private void processResponse(HttpServletRequest req, HttpServletResponse res)
               throws ServletException, IOException
               String imageId = req.getParameter("Id");
               OutputStream out = res.getOutputStream();
               String amDef = "kokaugi.model.KokaugiModule";
               String config = "KokaugiModuleLocal";
               ApplicationModule am = null;
               try
                   am = Configuration.createRootApplicationModule(amDef, config);
                   ViewObject vo = am.findViewObject("ADokumentiDati1");
                   if (imageId != null)
                       vo.setWhereClause("A_DOKUMENTI_PK=:img_id_tab");
                       vo.defineNamedWhereClauseParam("img_id_tab", null, null);
                       vo.setNamedWhereClauseParam("img_id_tab", imageId);
                       String query = vo.getQuery();
                       System.out.println(query);
                       vo.executeQuery();
                   if (vo.getEstimatedRowCount() == 1)
                       Row currentRow = vo.first();
                       String contentType = (String) currentRow.getAttribute("DokumentaTips");
                       if (contentType.equals("image/jpeg") || contentType.equals("image/gif") ||
                           contentType.equals("image/png"))
                           BlobDomain image = (BlobDomain) currentRow.getAttribute("Dokuments");
                           res.setContentType(contentType);
                           InputStream is = image.getInputStream();
                           byte[] buffer = new byte[10 * 1024];
                           int nread;
                           while ((nread = is.read(buffer)) != -1)
                               out.write(buffer, 0, nread);
                           out.flush();
                           out.close();                  
                           is.close();
                           image.closeInputStream();
                           // Remove the temporary viewobject
                           vo.closeRowSet();
                           vo.remove();                   
               catch (Exception ex)
                   ex.printStackTrace();
               finally
                   Configuration.releaseRootApplicationModule(am, false);
} Hope this helps, best regards, Debuger!
Edited by: Debuger on Oct 7, 2010 12:48 AM

Similar Messages

  • How to read from BLOB and Write to a file in user readable format.

    Hi,
         I am trying to read from a BLOB column and write the content to a file in user readable format. So far I was able to read the Blob column using dbms_lob, but not able to write to a file. Kindly let me know the method to do this.

    Hi, with this Java Code from Oracle Technet it's a easy thing:
    // classpath= /ORACLE/u01/app/oracle/product/10.2.0.3/jdbc/lib/ojdbc14.jar
    // Java SQL classes
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    // Oracle JDBC driver class
    import oracle.jdbc.OracleDriver;
    // Java IO classes
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    //Java Util classes
    import java.util.Properties;
    * This class demonstrates the Oracle JDBC 10g enhanced features for inserting
    * and retrieving CLOB data from the database. Using the new features, large
    * data of more than 32765 bytes can be inserted into the database using the
    * existing PreparedStatement.setString() and PreparedStatement.getString()
    * methods.
    public class ClobMan {
    /* Database Connection object */
    private Connection conn = null;
    /* Variables to hold database details */
    private String url = null;
    private String user = null;
    private String password = null;
    // Create a property object to hold the username, password and
    // the new property SetBigStringTryClob.
    private Properties props = new Properties();
    /* String to hold file name */
    private String fileName = null;
    * Default Constructor to instantiate and get a handle to class methods
    * and variables.
    public ClobMan(String fileName) {
    this.fileName = fileName;
    * Main runnable class.
    public static void main(String[] args) throws SQLException {
    // Instantiate the main class.
    ClobMan clobMan = new ClobMan(args[0]);
    // Load the Oracle JDBC driver class.
    DriverManager.registerDriver(new OracleDriver());
    // Load the database details into the variables.
    String dbUrl = "jdbc:oracle:thin:@pmol:1550:dbpmol";
    clobMan.url = dbUrl;
    clobMan.user = "gh10";
    clobMan.password = "secret";
    // Populate the property object to hold the username, password and
    // the new property 'SetBigStringTryClob' which is set to true. Setting
    // this property allows inserting of large data using the existing
    // setString() method, to a CLOB column in the database.
    clobMan.props.put("user", clobMan.user );
    clobMan.props.put("password", clobMan.password);
    clobMan.props.put("SetBigStringTryClob", "true");
    // Check if the table 'CLOB_TAB' is present in the database.
    //clobMan.checkTables();
    // Call the methods to insert and select CLOB from the database.
    //clobMan.insertClob();
    clobMan.selectClob();
    * This method will insert the data into a CLOB column in the database.
    * Oracle JDBC 10g has enhanced the existing PreparedStatement.setString()
    * method for setting the data more than 32765 bytes. So, using setString(),
    * it is now easy to insert CLOB data into the database directly.
    private void insertClob() throws SQLException {
    // Create a PreparedStatement object.
    PreparedStatement pstmt = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query to insert data into the CLOB column in the database.
    String sql = "INSERT INTO clob_tab VALUES(?)";
    // Read a big file(larger than 32765 bytes)
    String str = this.readFile();
    // Create the OraclePreparedStatement object
    pstmt = conn.prepareStatement(sql);
    // Use the same setString() method which is enhanced to insert
    // the CLOB data. The string data is automatically transformed into a
    // clob and inserted into the database column. Make sure that the
    // Connection property - 'SetBigStringTryClob' is set to true for
    // the insert to happen.
    pstmt.setString(1,str);
    // Execute the PreparedStatement
    pstmt.executeUpdate();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and inserting into " +
    "the database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and inserting into the" +
    " database table: " + ex.toString());
    } finally {
    // Close the Statement and the connection objects.
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * This method reads the CLOB data from the database by using getString()
    * method.
    private void selectClob() throws SQLException {
    // Create a PreparedStatement object
    PreparedStatement pstmt = null;
    // Create a ResultSet to hold the records retrieved.
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create SQL query statement to retrieve records having CLOB data from
    // the database.
    String sqlCall = "SELECT rownum, name, sourcetext FROM t_source";
    pstmt= conn.prepareStatement(sqlCall);
    // Execute the PrepareStatement
    rset = pstmt.executeQuery();
    String rownum = null;
    String o_name =null;
    String clobVal = null;
    // Get the CLOB value from the resultset
    //java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter("pr_all.sql"));
    while (rset.next()) {
    rownum = rset.getString(1);
         o_name = rset.getString(2);
         clobVal = rset.getString(3);
    System.out.println(" length: "+clobVal.length()+" "+o_name+" "+rownum);
         java.io.BufferedWriter out =
         new java.io.BufferedWriter(new java.io.FileWriter(o_name+".prc"));
         out.write(clobVal);
         out.newLine();
         out.write("/");
         out.newLine();
         out.newLine();
    out.flush();
    out.close();
    } catch (SQLException sqlex) {
    // Catch Exceptions and display messages accordingly.
    System.out.println("SQLException while connecting and querying the " +
    "database table: " + sqlex.toString());
    } catch (Exception ex) {
    System.out.println("Exception while connecting and querying the " +
    "database table: " + ex.toString());
    } finally {
    // Close the resultset, statement and the connection objects.
    if (rset !=null) rset.close();
    if (pstmt!=null) pstmt.close();
    if (conn!=null) conn.close();
    * Method to check if the table ('CLOB_TAB') exists in the database; if not
    * then it is created.
    * Table Name: CLOB_TAB
    * Column Name Type
    * col_col CLOB
    private void checkTables() {
    Statement stmt = null;
    ResultSet rset = null;
    try {
    // Create the database connection, if it is closed.
    if ((conn==null)||conn.isClosed()){
    // Connect to the database.
    conn = DriverManager.getConnection( this.url, this.props );
    // Create Statement object
    stmt = conn.createStatement();
    // Check if the table is present
    rset = stmt.executeQuery(" SELECT table_name FROM user_tables "+
    " WHERE table_name = 'CLOB_TAB' ");
    // If the table is not present, then create the table.
    if (!rset.next()) {
    // Table does not exist, create it
    stmt.executeUpdate(" CREATE TABLE clob_tab(clob_col CLOB)");
    } catch (SQLException sqlEx) {
    System.out.println("Could not create table clob_tab : "
    +sqlEx.toString());
    } finally {
    try {
    if( rset != null ) rset.close();
    if( stmt != null ) stmt.close();
    if (conn!=null) conn.close();
    } catch(SQLException ex) {
    System.out.println("Could not close objects in checkTables method : "
    +ex.toString());
    * This method reads the specified text file and, returns the content
    * as a string.
    private String readFile()
    throws FileNotFoundException, IOException{
    // Read the file whose content has to be passed as String
    BufferedReader br = new BufferedReader(new FileReader(fileName));
    String nextLine = "";
    StringBuffer sb = new StringBuffer();
    while ((nextLine = br.readLine()) != null) {
    sb.append(nextLine);
    // Convert the content into to a string
    String clobData = sb.toString();
    // Return the data.
    return clobData;
    }

  • Linking to new page from BLOB image in report

    Hi Guys,
    I have added an image to my report using the number/Date format field IMAGE:CITIES:CTY_PHOTO:CTY_NR::::::inline:Download. This works great! :)
    I know want the user to click on the image and go to the next page, setting the city code that was selected.
    If I try to add the Column Link Link Text in the usual way I get an error:
    report error:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    Any ideas?
    Thanks in advance,
    Fred

    We had a similar problem - this helped.
    Roger

  • I cannot display image (read from oracle BLOB field) on browser?

    I cannot display image (read from oracle BLOB field) on browser?
    Following is my code, someone can give me an advise?
    content.htm:
    <html>
    <h1>this is a test .</h1>
    <hr>
    <img  src="showcontent.jsp">
    </html>showcontent.jsp:
    <%@ page import="com.stsc.util.*" %>
    <%@ include file="/html/base.jsp" %>
    <% 
         STDataSet data = new STDataSet();
    //get blob field from database     
         String sql = "SELECT NR FROM ZWTAB WHERE BZH='liqf004' AND ZJH='001'";
         //get the result from database
         ResultSet rs = data.getResult(sql,dbBase);
         if (rs!=null && rs.next()) {
              Blob myBlob = rs.getBlob("NR");
              response.setContentType("image/jpeg");//
              byte[] ba = myBlob.getBytes(1, (int)myBlob.length());
              response.getOutputStream().write(ba);
              response.getOutputStream().flush();
         // close your result set, statement
         data.close();     
    %>

    Don't use jsp for that, use servlet. because the jsp engine will send a blank lines to outPutStream corresponding to <%@ ...> tags and other contents included in your /html/base.jsp file before sending the image. The result will not be treated as a valid image by the browser.
    To test this, type directly showcontent.jsp on your browser, and view it source.
    regards

  • Read Image file from BLOB.

    Hi All,
    I am trying to load data from BLOB data from database and save the image file.
    SQL to insert data:
    INSERT INTO BLOBTest (BLOBName, BLOBData)
    SELECT 'First test file', BulkColumn FROM OPENROWSET(Bulk 'C:\Inbound\logo.jpg', SINGLE_BLOB) AS BLOB
    I am using the following 'SELECT top 1 BLOBData from BLOBTest' to get the data and setting the value to 'Image Saver' action. The image file is saved to the specified path, but the image is not opening.
    I get "Image is damaged, corrupted or is too large message. The file is around 40 KB."
    Am i missing something.
    Any help would be highly appreciated.
    MII Version: 14.0 SP 3
    Thanks,

    I think this thread might help: Can we interpret Oracle BLOB data in SAP MII and how?
    Basically MII doesn't support the BLOB/CLOB data types so in your query you will need to convert it to a base64 string that MII can consume using the image saver action.
    Regards,
    Christian

  • Problem Displaying image from blob

    Hi all,
    I m using,
    Database : 10g Rel 2
    Frontend : DevSuite 10g
    OS : WinXp
    Browser : IE 6
    Problem : In my forms i m displaying images from blob column but some of the images are not displayed. I have tried with all image formats available in combination with all available display quality but no luck. What could be the reason for it and how do i solve it?
    Can anyone help me plz?
    Thnx in advance.
    Imtiaz

    Hello,
    It is very difficult for us to "guess" what images you can read and what others you cannot.
    Maybe you could provide more information on images that are not displayed ?
    What is their native format ?
    Francois

  • Servlet not showing BLOB image from Oracle in JSF

    hi forum.
    i have a table in oracle in which i m storing images in a BLOB field and file extention (mime type) in a varchar2 field. i can successfully store image. but i want the stored image to be displayed in a graphicimage tag from BLOB. i searched net and found it has to be done using servlet. the code that i used is as following. but i get null pointer exceptions. i know i should get these exceptions but i dont know how to tackle them since there were few things left vague in every site i searched. so i opted to ask the forum.
    here is the code for my jsp page
         <h:graphicImage value="/DisplayImage"/>
    web.xml is amended as follows
                  <servlet>
      <servlet-name>DisplayImage</servlet-name>
      <servlet-class>imageDisplay.DisplayImage</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>DisplayImage</servlet-name>
      <url-pattern>/DisplayImage</url-pattern>
    </servlet-mapping>
              the servlet itself....
       package imageDisplay;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.pa.utils.HibernateUtils;
    import org.hibernate.Session;
    public class DisplayImage extends  HttpServlet{
      public void doGet(HttpServletRequest request,HttpServletResponse response)  throws ServletException, IOException
                Session hibernateSession = null;
              hibernateSession = HibernateUtils.currentSession();
              Connection connection;
              connection = hibernateSession.connection();
              Statement st1;
      try{ 
           Class.forName("oracle.jdbc.driver.OracleDriver");
             st1=connection.createStatement();
             ResultSet rs1 = st1.executeQuery("select APP_FILE from EMPLOYEE_DETAILS where EMP_ID = 2");  //APP_FILE IS THE BLOB FIELD
             System.out.println("----------------#@$#@$$%^$%^%&^*^&*(&(*&^%$#$%@#%^%^%&*&^*$^&#%^$%@#$%@#$--------------------");
           String imgLen="";
           while(rs1.next())
           imgLen = rs1.getString(1);
                      int len = imgLen.length();   //THIS IS LINE 35 WHERE ERROR IS EMERGED...............
                     byte [] rb = new byte[len];
                     InputStream readImg = rs1.getBinaryStream(1);
                     int index= readImg.read(rb, 0, len); 
                System.out.println("index----#@$#@$$%^$%^%&^*^&*(&(*&^%$#$%@#%^%^%&*&^*$^&#%^$%@#$%@#$------------"+index);
                response.reset();
                response.setContentType("image/jpg");
                response.getOutputStream().write(rb,0,len);
                response.getOutputStream().flush();
      st1.close();
      response.getOutputStream().close();
    } catch (Exception e){
      e.printStackTrace();
      the error i get is
    index----#@$#@$$%^$%^%&^*^&*(&(*&^%$#$%@#%^%^%&*&^*$^&#%^$%@#$%@#$------------
    java.lang.NullPointerException
         at imageDisplay.DisplayImage.doGet(DisplayImage.java:35)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
         at java.lang.Thread.run(Unknown Source)bundle of thanks in advance for reading my problem persistantly and your help that i am desperately looking for
    Edited by: jaykio77 on Jan 11, 2012 4:09 AM
    Edited by: jaykio77 on Jan 11, 2012 4:12 AM

    In stead of copying/pasting code, take the time to read about how JDBC works. Yes that is going to take some time, but when you gain the knowledge you prevent yourself from having to dump your problem on other people, in this case a bunch of friendly strangers.
    This code:
    imgLen = rs1.getString(1);
                      int len = imgLen.length();   //THIS IS LINE 35 WHERE ERROR IS EMERGED...............
                     byte [] rb = new byte[len];
                     InputStream readImg = rs1.getBinaryStream(1);Really doesn't make much sense. This would assume that the first position in the resultset is both a String and a Blob.
    In the mean time, break down your problem. What you want to do is read a blob from a resultset. Right? Thats it, who cares that a servlet is involved, that is not what you are having trouble with. You cannot read the blob.
    That is vital to realize as you can narrow your google search to "java resultset blob". Guess what popped up as the first hit for me:
    http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetBLOBdatafromresultset.htm

  • Forms6i, read and write Images to BLOB

    I read and write jpg's to the database with this commands:
    Read_Image_File (V_Filename, 'JPG', 'BILDER.IM_BILD');
    Write_Image_File (V_Filename, 'JPG', 'BILDER.IM_BILD', No_Compression, Original_Depth);
    My problem is, that forms stores a jpg-format to the db, that cannot be read from java-programs.
    The other way, when java stores jpg's to the BLOB, then forms can work fine with this images too and java also...
    What does forms do, when it stores jpg's to the db, so that other programs cannot use the images?
    Gerd

    When you post code, please use the code tags using the code button available on the message entry page. It makes it much easier to read.
    Do you have a question?

  • Reading grayscale values from saved image

    Hi,
    I've written several methods that crop, convert to grayscale, histogram equalise and then resize a colour jpeg image for preparing sets of images for a face detection neural network. The next thing I want to do is to write a method that allows me to read that saved grayscale images pixel values back as singular grayscale values from the RGB values that were used to save the jpeg. I used this code to create the 2D array of grayscale pixel values
          for (int i = 0; i < imageWidth; i++)
                for (int j=0; j <imageHeight; j++)
                    grayRGB[i][j] = (rgb[i][j] & 0xff000000) | (eqGray[i][j]<<16) | (eqGray[i][j]<<8) | (eqGray[i][j]);
                    img.setRGB(i, j, grayRGB[i][j]);
                }and then used this code to resize the image:
            BufferedImage resized = new BufferedImage(20,20,1);
            Graphics2D g = resized.createGraphics();
            g.drawImage(img, 0, 0, 20, 20, null);
            g.dispose();my class gets the RGB values on instantiation as follows:
            //get RGB pixel values for image loaded
            for (int i = 0; i < imageWidth; i++)
                for (int j=0; j <imageHeight; j++)
                    rgb[i][j]= inputImage.getRGB(i,j);
                    //perform bitwise shift rgb information values to obtain appropriate values for each colour pixel
                    r[i][j]=  (rgb[i][j] >> 16) &0xff;
                    g[i][j]=  (rgb[i][j] >> 8) &0xff;
                    b[i][j]=  (rgb[i][j]) &0xff;
                }Is there a way to get the grayscale values directly from an image that is already converted to grayscale without having to perform the grayscale conversion method again, perhaps using a similar bitwise shift?
    Thanks
    Nick

    answering this myself for those lost souls like i was a while ago:
    the answer is very simple when you get to know it :) : use a signed type for your image. this can be achieved by using the Format Operator (javax.media.jai.operator.FormatDescriptor). an example as follows :
            BufferedImage bufferedImage= someimage...
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(bufferedImage);
            pb.add(DataBuffer.TYPE_SHORT);
            RenderedImage formattedImage =
                    JAI.create("format", pb, null);
    // you may use as well TYPE_DOUBLE or TYPE_FLOATimage could be of any type such as PlanarImage, BufferedImage, RenderedImage etc..
    then all you need to do is read your pixel values by using an iterator such as RectIter or RandomIter to access pixel values etc..
    San

  • Display image in report from BLOB

    Hi All,
    i have one requirement i.e
    i want to display image in a report base on condition
    like if id =1 then firest image, id = 2 then second image and id =3 then third image
    i have image in database in BOLB type
    i need to display in report based on that condition
    please help me this requirement is urgent
    reg,
    jell

    just create a query like this:
    select id, image_name, image
    from tablethen your XML output would be like this:
    <ROWSET>
         <ROW>
              <ID>1</ID>
              <IMAGE_NAME>kljkla</IMAGE_NAME>
              <IMAGE>Lots of characters that represents the BLOB</IMAGE>
         </ROW>
         <ROW>
              <ID>2</ID>
              <IMAGE_NAME>jdkwel</IMAGE_NAME>
              <IMAGE>Lots of characters that represents the BLOB</IMAGE>
         </ROW>
         <ROW>
              <ID>3</ID>
              <IMAGE_NAME>oled</IMAGE_NAME>
              <IMAGE>Lots of characters that represents the BLOB</IMAGE>
         </ROW>
         <ROW>
              <ID>4</ID>
              <IMAGE_NAME>mlish</IMAGE_NAME>
              <IMAGE>Lots of characters that represents the BLOB</IMAGE>
         </ROW>
    </ROWSET>in your RTF you put this:
    <fo:instream-foreign-object content-type="image/jpg" width="251.8pt" height="174.3pt" xdofo:alt="picture"><xsl:value-of select=".//IMAGE"/></fo:instream-foreign-object>the attributes width and height are optional

  • How to read a XML file from BLOB column and insert in a table - PL/SQL Only

    Hi,
    To make data load more simple to end user instead placing file on the server and use SQL-LOADER, I came up with new idea that using oracle ebusiness suite attachment functionality. that loads a XML file from local PC to a database column(table is fnd_attachments, default data type is BLOB over here).
    I tried with DBMS_LOB and didnt get around.
    Please can anyone tell me how to read the BLOB column using PL/SQL and store the data in a oracle table. Here's the sample XML file and table structure FYI.
    <?xml version="1.0" encoding="UTF-8"?>
    <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Corporate_alloc.xsd" generated="2009-07-07T14:17:49">
    <Corporate_alloc>
    <PKG_CODE>BKCORP</PKG_CODE>
    <PKG_NAME>Corporate Edition - Books</PKG_NAME>
    <DET_CODE>B9780080543758</DET_CODE>
    <DET_NAME>Waves, Tides and Shallow-Water Processes</DET_NAME>
    <ALLOCATION_RATIO>0.000041</ALLOCATION_RATIO>
    </Corporate_alloc>
    <Corporate_alloc>
    <PKG_CODE>BKCORP</PKG_CODE>
    <PKG_NAME>Corporate Edition - Books</PKG_NAME>
    <DET_CODE>B9780080534343</DET_CODE>
    <DET_NAME>Hydrostatically Loaded Structures</DET_NAME>
    <ALLOCATION_RATIO>0.000127</ALLOCATION_RATIO>
    </Corporate_alloc>
    </dataroot>
    CREATE TABLE TEST_XML
    ( PKG_CODE VARCHAR2(50),
    PKG_NAME VARCHAR2(100),
    DET_CODE VARCHAR2(20),
    DET_NAME VARCHAR2(500),
    ALLOCATION_RATIO NUMBER )
    Thanks
    EBV

    In regards to #3, use the COLUMNS functionality of XMLTable instead of using Extract. Two simple examples are
    Re: XML Data - Caliculate fields
    Re: Extractvalue function not recognised

  • Displaying image from BLOB from DB in Browser

    I have a PL/SQL procedure to create a table with a BLOB image, mime type, key, etc. I can use another PL/SQL to load the images into the table. I have a PL/SQL procedure to get an image. I would like to call this procedure and pass the key parameter to display an image in a browser using HTML. Does anyone know how to do this?
    Thanks.

    Use a java servlet to call your stored procedure (using jdbc), this will return the image as a java blob class. You can then write the java blob bytestream to the servlet response object, this should then appear in the browser.

  • Display image from BLOB field (png image)

    Hello,
    On my database i have a function which return BLOB (png image from a webservice)..
    Is there some tutorial or sample code how to display a image froma blob field in oracle reports?
    thank you

    You can create a view and base your report on that view. The view would be something like:
    create or replace view my_view as
    select my_blob_function() image
    from ...In your Report it would just be:
    select image
    from my_viewNow, I'm not sure if Reports supports png format, though.
    There are many examples to be found, e.g.
    http://download.oracle.com/docs/html/B10602_01/orbr_dyngraph.htm

  • Plesae help- needing to read a blob from db into bytes[]

    Hi all,
    I am having a requirement to read a blob stored in the oracle table and convert it into bytes. I am loading this table (wwv_flow_files) with APEX.
    The code under page 1 is as follows:
    DECLARE
    z number;
    y varchar2(4000);
    x varchar2(400);
    b blob;
    BEGIN
    select filename,blob_content into x ,b from APEX_APPLICATION_files where name =:P1_FILE_NAME;
    select length(convertBlobToBytes(b)) into z from dual;
    :P1_RESULT := z;
    end;
    Java code is as follows:
    import java.io.*;
    import java.sql.Blob;
    public class convertBlob {
    * @param blob
    * @return
    public static byte[] convertBlobToBytes(Blob blob) {
         if (blob==null) return null;
         try {
         InputStream in = blob.getBinaryStream();
         int len = (int) blob.length(); //read as long     
    long pos = 1; //indexing starts from 1
         byte[] bytes = blob.getBytes(pos, len);           
    in.close();
         return bytes;     
    catch (Exception e) {
         System.out.println(e.getMessage());
         return null;
    PL/SQL wrapper is as follows:
    CREATE OR REPLACE FUNCTION convertBlobToBytes(p1 IN BLOB) RETURN LONG RAW AUTHID CURRENT_USER AS LANGUAGE JAVA NAME 'convertBlob.convertBlobToBytes(java.sql.Blob) return byte[]';
    I loaded this java class and pl/sql wrapper into the database using JDEVELOPER.
    But I am getting the length of the file, as twice the size.
    For example, When I run the program which reads the file returns the length of the file as a byte array, the length is 819.
    When I pass the same file as a blob from apex, to the java program that converts blob to bytes, the length of the file is 1638.
    And hence I am getting wrong results, further in the process.
    Can you please help me? Any help is appreciated.
    rgds,
    Suma.

    Hi all,
    Can any of you please help me out?
    rgds,
    Suma.

  • How to load images from BLOB to javascript?

    hi, Guys:
    I need to load thumbnail images from BLOB to multiple markers' infowindow in Google map . I have implemented Google map in APEX. I load the data suchas text for every marker's infowindow from Oracle database table with PL/JSON, and infowindow works fine. Could anyone give me a suggestion or example so I know how to load images to javascript?
    Thanks a lot.
    Database: Oracle 11g R2
    APEX: APEX 4.1
    Thanks.
    Sam

    lxiscas wrote:
    hi, VC:
    Thanks for your kind reply. I need to render these images out of APEX session, actually in javascript that is related to Google map markers' infowindow.
    I checked the documents of APEX_UTIL.GET_BLOB_FILE_SRC, but my impression is I need to use it in APEX instead of javascript if my understanding is correct. I already implemented a procedure with PL/SQL to load images from a BLOB column in Oracle database. But the problem is, how can I pass it to javascript code out of APEX to javascript (I could pass text or number from APEX to javascript with PL/JSON though,But I assume that still google map will be within a valid apex session? if so you should be able to use the above api.
    Basically what this api does is generates a kind of url to each blob in the database, not sure how google api's deal with this though. Why don't you give it a try?
    The other option is to make your pl/sql procedure public and then you can generate the json to include the images urls such as:
         "employees" : [{
                   "firstName" : "John",
                   "lastName" : "Doe",
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Anna",
                   "lastName" : "Smith"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Peter",
                   "lastName" : "Jones"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
    }And then you can use this new attribute to populate the images in javascript using standard img tag
    See this tutorial http://docs.oracle.com/cd/E14373_01/appdev.32/e13363/up_dn_files.htm
    I did not find any method in PL/JSON to pass image object)? So far I only found example to load images from local files to javascript.Hmm..I don't think you should load image objects.
    Vikram

Maybe you are looking for

  • My iPhone 5 won't allow me to download ANY apps.

    I click in the purchase icon, the blue circle comes up like its loading but then a minute later a msg pops up saying "unable to purchase, (app I'm trying to download) could not be purchased at this time. Please try again later". But every time I try

  • Issue with adding new fonts in Lion

    I'm trying install two new fonts on my Mac Book Air and cannot get it to allow me to add them to the Font Book. (I've just successfully added the same fonts on to my Mac Book Pro which runs Snow Leopard, so this is definitely a Lion issue.) I've crea

  • Error while installing applications

    Hi I am getting an error while installing applications in snow leopard. I got this error couple of times while I was installing different applications. Below is the details of the error. System extension cannot be used (The system extension "/System/

  • Need report output to be display in 'XML' format.

    Hi ALL, I have a requirement to generate a report in different format like 'PDF','EXCEL' AND 'XML' in my OAF page. for 'PDF' i am able to generate report after selecting the output fromat from my choicebox through below code : DocumentHelper.exportDo

  • Multiple Selection multi-line per choice

    I have a bunch of multiple selection items which are all the same, so I copied and pasted them where I wanted them. The pasted ones are taking up two to three lines per choice (one word per line) even though they are very short and the original that