How to display every other images in image indicator

Hi All,
I am using IMAQ to grab and save high freq and high resolution images. I have an image indicator directly from "Image Grab Acquire". So, the image indicator is displaying every single images at a very high frequency too. We have to display frames, but not necessarily every single one (enough so the operator can see what's going on). So, I am wondering how I can display, say every other images (such as all odd/even number of images), or jump over two and display the third?
Any help will be appreciated!
Thanks!
Wenlong
Solved!
Go to Solution.

Here are some general comments.
Image acquisition is "a horse of a different color" -- unlike many other I/O devices, the memory that holds the data (here called the "buffer") is managed by the driver, and isn't directly available to LabVIEW.
I'm guessing that you are using NI Video hardware, as you are using IMAQ functions (I've only used IMAQdx).  Is this true?  What camera are you using?
The IMAQ Extract Buffer (probably) "clocks" itself to the camera (I say "probably" because I don't know the hardware you are using).  This means that the While loop containing it will run at the frame rate of the camera (hence you can easily calculate the frame rate, as your code shows).
This looks like an NI Demo routine, so I'm guessing that you don't have a lot of experience with Vision processing.  If you've got a lot of other LabVIEW experience, you should be able to make the leap to vision, once you get the idea of how buffers work.  Unfortunately, there's not as much in the way of tutorials and white papers on Vision as on other LabVIEW topics.
So to your question -- how to display every Nth image.  Here's the key loop (which is lifted directly from your code):
As menioned above, this routine is "clocked" by the Extract Buffer function.  What you do to display every N'th image is to put the Image control inside something like a Case statement that "fires" every Nth time.  
Here's an "Nth" version of the above loop (some details omitted) --
We still drive the loop filling every buffer with a frame.  But we then use the Integer Divide function to select the Nth image (those that have a remainder of 0 when i is divided by Nth) and wire the "image" line (it doesn't really hold an image) to the "Image" control, with the other case being "Default" (so all other valeus go there) and with nothing inside.  Thus every Nth time through this loop, the output of Extract Buffer is wire to an Image (and displayed), the other N-1 times the wire goes nowhere.
Bob Schor

Similar Messages

  • Does anyone knows how to highlight every other row in numbers mac

    Does anyone knows how to highlight every other row in numbers and are there any good tutorials out there???

    Hi Lee,
    Select a non-header cell in the table.
    Open the Inspector and choose the Table Inspector.
    Click to check the 'Alternating Row Color' box in the Cell Background section.
    Click the Color well beside the check box to open the Color pane.
    Choose a colour.
    The alternating colours are applied only to the non-header rows and non-header columns in your table.
    Regards,
    Barry

  • How to display non-URL-based thumbnail images in JTable

    I'm trying to display thumbnail images as a tooltip popup for certain cells in a JTable. The thumbnail images are java image objects that have been retrieved dynamically as the result of a separate process--there is no associated URL. For this reason, I can't use the setToolTipText() method of the JTable.
    My attempts to JTable's createToolTip() method also failed as it seems the ToolTipManager never calls this method for a JTable.
    As a workaround, I've added a MouseMotionListener to the JTable that detects when the mouse is over the desired table cells. However, I'm not sure how to display the popup over the JTable. The only component that I can get to display over the JTable is a JPopupMenu, but I don't want to display a menu--just the image. Can anyone suggest a way to display a small popup image over the table?
    Thanks.

    Thank You Rodney. This explains why my createToolTip() method wasn't being called, but unfortunately I'm no closer to my goal of displaying a true custom tooltip using a non-URL image rather than a text string. If I make a call to setToolTipText(), at any point, the text argument becomes the tooltip and everything I have tried in createToolTip() has no effect. However, as you pointed out, if I don't call setToolTipText(), the table is not registered with the tooltip manager and createToolTip() is never even called.
    To help clarify, I have attached an SSCCE below. Please note that I use a URL image only for testing. In my actual application, the images are available only as Java objects--there are no URLs.
    import javax.swing.*;
    import java.awt.*;
    import java.net.URL;
    import java.net.MalformedURLException;
    public class Test {
        static Object[][] data = {
                {"Cell 0,0", "Cell 0,1"},
                {"Cell 1,0", "Cell 1,1"}};
        static String[] columnNames = {"Column 0", "Column 1"};
        static JFrame frame;
        static String testImageURLName = "http://l.yimg.com/k/omg/us/img/7c/0a/4009_4182164952.jpg";
        static JTable testTable = new JTable(data, columnNames) {
            public JToolTip createToolTip() {
                System.out.println("testTable.createToolTip() called");
                Image testImage = getTestImage();
                // this.setToolTipText("Table ToolTip Text");
                JLabel customTipLabel = new JLabel(new ImageIcon(testImage));
                customTipLabel.setToolTipText("Custom ToolTip Text");
                JToolTip parentTip = super.createToolTip();
                parentTip.setComponent(customTipLabel);
                return parentTip;
        // This image is loaded from a URL only for test purposes!!!
        // Ordinarily, the image object would come from the application
        // and no URL would be available.
        public static Image getTestImage() {
            try {
                URL iconURL = new URL(testImageURLName);
                ImageIcon icon = new ImageIcon(iconURL);
                return icon.getImage();
            catch (MalformedURLException ex) {
                JOptionPane.showMessageDialog(frame,
                        "Set variable \"testImageName\" to a valid file name");
                System.exit(1);
            return null;
        public static void main(String[] args) throws Exception {
            frame = new JFrame("Test Table");
            frame.setSize(300, 100);
            // Set tool tip text so that table is registered w/ tool tip manager
            testTable.setToolTipText("main tooltip");
            frame.getContentPane().add(testTable);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }

  • How to display a horizontal list of images

    Hello everyone,
    I am new to Flash Builder 4 and I am looking to display a horizontal list of images on my Flex Mobile Project (using Burrito Flash Builder). Can anyone recommend me what component that I should use?
    I know the <s:List /> will display a Vertical list of items, but I am not sure what component to display a horizontal list of items.
    Thanks in advance for any help,

    Have you tried using HorizontalList?
    Here is an example:
    http://flex4fun.com/2010/11/30/flex4-horizontallist-example/

  • How to display different parts of an image

    hi,
    I need to display different parts of an image at specific situations.
    for example, a dice. there is only one image which includes different sides of the dice. and I wanna add
    to my panel one side if one comes, two side if two comes... I mean if one comes then we will display
    from 10 px to 80 px width and from 10 px to 80 px height of the dice image.
    is there any way to obtain this in java?
    thanks...

    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.util.Random;
    import javax.swing.*;
    public class ImageClipping extends JPanel {
        BufferedImage image;
        Rectangle clip;
        final int ROWS = 3;
        final int COLS = 3;
        public ImageClipping() {
            // Make an image we can clip.
            Dimension d = getPreferredSize();
            int type = BufferedImage.TYPE_INT_RGB;
            image = new BufferedImage(d.width, d.height, type);
            Graphics2D g2 = image.createGraphics();
            g2.setBackground(getBackground());
            g2.clearRect(0, 0, d.width, d.height);
            Font font = g2.getFont().deriveFont(36f);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            float sh = lm.getAscent() + lm.getDescent();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            for(int j = 0; j < ROWS; j++) {
                for(int k = 0; k < COLS; k++) {
                    String s = String.valueOf(j*COLS + k+1);
                    float sw = (float)font.getStringBounds(s, frc).getWidth();
                    float sx = k*xInc + (xInc - sw)/2;
                    float sy = j*yInc + (yInc + sh)/2 - lm.getDescent();
                    g2.setPaint(Color.red);
                    g2.drawString(s, sx, sy);
                    g2.setPaint(Color.blue);
                    g2.drawRect(k*xInc, j*yInc, xInc-1, yInc-1);
            g2.dispose();
            clip = new Rectangle(xInc, yInc);
            // Inspect image.
            ImageIcon icon = new ImageIcon(image);
            JOptionPane.showMessageDialog(null, icon, "", -1);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            Shape origClip = g2.getClip();
            //g2.setPaint(Color.red);
            //g2.draw(clip);
            // Draw clipped image at:
            int x = 100;
            int y = 100;
            // Mark location.
            g2.setPaint(Color.red);
            g2.fill(new Ellipse2D.Double(x-2,y-2,4,4));
            // Position the image.
            g2.translate(x-clip.x, y-clip.y);
            // Clip it and draw.
            g2.setClip(clip);
            g2.drawImage(image,0,0,this);
            // Reverse the changes to the graphics context.
            g2.setClip(origClip);
            g2.translate(clip.x-x, clip.y-y);
        public Dimension getPreferredSize() {
            return new Dimension(400,400);
        public static void main(String[] args) {
            ImageClipping test = new ImageClipping();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test);
            f.pack();
            f.setLocation(50,50);
            f.setVisible(true);
            test.start();
        private void start() {
            Thread thread = new Thread(runner);
            thread.setPriority(Thread.NORM_PRIORITY);
            thread.start();
        private Runnable runner = new Runnable() {
            Random seed = new Random();
            Dimension d = getPreferredSize();
            int xInc = d.width/COLS;
            int yInc = d.height/ROWS;
            public void run() {
                do {
                    try {
                        Thread.sleep(3000);
                    } catch(InterruptedException e) {
                        break;
                    int row = seed.nextInt(ROWS);
                    int col = seed.nextInt(COLS);
                    int x = col*xInc;
                    int y = row*yInc;
                    int n = row*COLS + col+1;
                    System.out.printf("row = %d  col = %d  n = %d%n",
                                       row, col, n);
                    clip.setLocation(x,y);
                    repaint();
                } while(isVisible());
    }

  • How to display a blob as an image

    I am working on an application which stores images in a database as blobs. I need to extract these images and display them from a web page. How do I go about this using JSP or JSF?
    Werner

    Thanks for the quick response, matlas. I should have included more info in my original post. I am familiar with reading/writing blobs from the database. The part I am stuck on is how does the java servlet return the blob (dPhoto below), to the web page?
    i.e. from <img src="employeePhoto.jsp&empId=123">
    ImageIcon dPhoto = null;
    // open connection
    Connection photoConnection = startup.openSQLConnection(SQLDriver, SQLConnectionString);
    // setup select string
    String sqlStatement = "select Binary_Photo from employeephoto where Employee_ID = '"+employeeID+"'";
    try {
    // perform select
    ResultSet rs = photoConnection.createStatement().executeQuery(sqlStatement);
    // if record found process blob
    if (rs.next()) {
    // get blob
    Blob image = rs.getBlob("Binary_Photo");
    // setup the streams to process blob
    InputStream input = image.getBinaryStream();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    // set read buffer size
    byte[] rb = new byte[1024];
    int ch = 0;
    // process blob
    while ((ch=input.read(rb)) != -1) {
    output.write(rb, 0, ch);
    // transfer to byte buffer
    byte[] b = output.toByteArray();
    input.close();
    output.close();
    // load final buffer to image icon
    dPhoto = new ImageIcon(b);
    catch (Exception exc) {/ do your exception processing}
    // close connection
    startup.closeSQLConnection(photoConnection);
    // dPhoto holds image or is null at this point.

  • How to display image in database using php

    i've try search all hope that you all can give me some guidance how to display data that is in image or BLOB using PHP. just a query and php code that will make display of the image. hope that you all show me the example or give me reference that i need to solve my problem.

    Hi,
    Have a check on these Google results, you might find something there...
    http://www.google.com/search?sourceid=navclient-ff&ie=UTF-8&q=%22display%20image%22%2Boracle%20%2Bphp

  • How to display Image by using Array?

    Hi all, I know to how to display the image in MXML by using
    AS 3.0
    like this:
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="100" height="80" borderStyle="solid">
    <mx:Script>
    <![CDATA[
    [Embed(source="logo.gif")]
    [Bindable]
    public var imgCls:Class;
    ]]>
    </mx:Script>
    <mx:Image source="{imgCls}"/>
    <!--OR-->
    <mx:Image source="@Embed('assets/Nokia_6630.png')"/>
    </mx:Application>
    But the thing is I am building a list for display the images,
    the values is come from the Array. I am trying a different way for
    display it but no working, here is my code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    public var PICTURE_ARRAY:Array = [{label:"FileA",
    icon:"@Embed('upload/myjpg.jpg')"},
    {label:"FileC", icon:"@Embed('upload/myjpg.jpg')"},
    {label:"FileB", icon:"@Embed('upload/myjpg.jpg')"}]
    ]]>
    </mx:Script>
    <mx:Tile id="pictureSelection" height="180" width="500"
    borderStyle="solid">
    <mx:Repeater id="picRP"
    dataProvider="{PICTURE_ARRAY}">
    <mx:VBox horizontalAlign="center" verticalAlign="middle"
    verticalGap="0" borderStyle="none" width="100" height="100">
    <mx:Image width="80" height="80"
    source="{picRP.currentItem.icon}"
    toolTip="{picRP.currentItem.icon}"/>
    <!--
    I also tryed this as well:
    set the icon value as picture location like: "A.jpg" or
    "B.jpg"
    then
    <mx:Image width="80" height="80"
    source="@Embed('upload/{picRP.currentItem.icon}')" />
    -->
    <mx:Label text="{picRP.currentItem.label}" width="100"
    textAlign="center"/>
    </mx:VBox>
    </mx:Repeater>
    </mx:Tile>
    </mx:Application>
    Can anyone tell how to display the array value into Image
    tag? Thanks

    In your data you have this:
    {label:"FileC", icon:"@Embed('upload/myjpg.jpg')"},
    change it to this:
    {label:"FileC", icon:"upload/myjpg.jpg"}, // this is just the
    filename, not embedded
    In your Repeater you have this Image tag:
    <mx:Image width="80" height="80"
    source="{picRP.currentItem.icon}"
    toolTip="{picRP.currentItem.icon}"/>
    which is fine, except for the toolTip. The toolTip uses a
    string, not an image. If you want to show an image in the toolTip,
    you'll need to write your own toolTip class.
    Now the source property of the image will be given the URL to
    the image which will then be requested from the server and
    downloaded at runtime - it is not embedded.
    If you need to embed the images, then your dataProvider
    should have the variable name associated with the embedded
    image.

  • How do i display every 10 Records in my JSP page??

    Hi..
    I have developed one web-page which shows ALL employee records fetched from a employee table and display them in my JSP page.
    It has contain more than 1000's of records. I need to display first 10 Records in my page. There should be some 4 links below the records display which get me to see next 10 records or previous 10 records or first 10 records or Last 10 records.
    IS it possible in JSP??
    This is my sample code for your ref:
    <jsp:useBean id="empOperation" class="com.venki.gen.EmployeeOperation" />
    <html>
    <head>
         <title>Stardeveloper : DataAccess JSP Tag</title>
         <style>
         p, td { font-family:Tahoma,Sans-Serif; font-size:8pt;
              padding-left:15; }
         </style>
    </head>
    <body>
    <p align="center"><u>DataAccess JSP Tag</u></p>
    <%
         EmployeeList empList[] = null;
         empList = empOperation.getEmployees(empName);
    %>
    <table align="center" border="0" width="90%" cellspacing="2" cellpadding="2">
    <tr bgcolor="#CCDDEE">
         <td>EMPNO</td>
         <td>EMP Name</td>
         <td>DESIGNATION</td>
    </tr>
    <%if(empList!=null)
         for(int i=0; i<empList.length; i++)
          EmployeeList emp = empList;%>
         <tr bgcolor="#F7F7F7">
         <td><%= emp.getEmpNo() %></td>
         <td><%= emp.getEmpName() %></td>
         <td><%= emp.getEmpDesignation()%></td>
         </tr>
         <% }%>
    </table>
    </body>
    </html>
    It would be extremely useful,if i know the technique how to display every 10 Records thru JSP.
    Waiting for You people valuable reply and code!
    Regards
    venki

    I do it by pages. i.e. http://example.com/page.jsp?page=1 would show records 1-10, ?page=2 would show records 11-20
    let's pretend each record is identified by one field in the database, `id`
    then the SQL query you'd use to grab the records could be..
    SELECT * FROM `your_table` WHERE `id` >= (page*10) and <= (page*10+10)or this might even work:
    SELECT * FROM `your_table` ORDER BY `id` ASC LIMIT (page*10),10(all examples untested as I'm at work :P)

  • Display a label for every other category on a graph

    I have a line graph created in Illustrator with years on the horizontal axis (1998, 1999, 2000, 2001, 2002, etc.). There is data for each year that will be plotted on the line, however I would only like to display every other year (1998, 2000, 2002, 2004, 2006, etc.). Is there a way to show every other year on the horizontal axis.

    I can't leave the years out because there is data for those years. In Excel, there is an option to 1 display a label for every category, 2 to display a label for every other category, 3 to display a label for every third category. How do you do it in Illustrator. My table looks something like this but begins in 1980.
    "2001"
    52
    "2002"
    56
    "2003"
    81
    "2004"
    84
    "2005"
    91
    "2006"
    97
    "2007"
    102
    "2008"
    103
    "2009"
    104
    "2010"
    110
    "2011"
    106

  • How to display different fonts in same indicator in labVIEW

    hi 
       i want to know how to display different fonts in same string indicator at run time in labVIEW 8.2
    Regards
    Abhishek Verma

    Hi ABHI VERMA,
    see this http://digital.ni.com/public.nsf/allkb/6BD344ACA4DEE20A8625692700737E16 
    Mike

  • Html query report /every other row grey

    Hello
    i have this query to html report
    do you know how to make every other row grey in the out pu of
    the query.
    and where do i put it in this code below?
    thanks in advance
    <cfquery name="GetCompanies"
    datasource="#Request.MainDSN#">
    SELECT
    CompanyID,
    CompanyName,
    Address,
    City,
    State,
    ZipCode,
    Comments
    FROM
    Company
    ORDER BY
    CompanyName ASC
    </cfquery>
    <html>
    <head>
    <title>ColdFusion MX Bible</title>
    <link rel="stylesheet" href="styles.css">
    </head>
    <body>
    <h1>Company List</h1>
    <TABLE width=100% align="left" border="4" rules="all">
    <tr>
    <td><b>ID</b></td>
    <td><b>Name</b></td>
    <td><b>Address</b></td>
    <td><b>City</b></td>
    <td><b>State</b></td>
    <td><b>ZIP Code</b></td>
    <td> </td>
    </tr>
    <cfoutput query="GetCompanies">
    <tr>
    <td>#CompanyID#</td>
    <td>#CompanyName#</td>
    <td>#Address#</td>
    <td>#City#</td>
    <td>#State#</td>
    <td>#ZipCode#</td>
    <td>
    <a
    href="EmployeeList.cfm?CompanyID=#CompanyID#">Employees</a>
    <a href="CompanyAddForm.cfm">Add</a>
    <a
    href="CompanyEditForm.cfm?CompanyID=#CompanyID#">Edit</a>
    <a
    href="CompanyDeleteForm.cfm?CompanyID=#CompanyID#">Delete</a>
    </td>
    </tr>
    </cfoutput>
    </TABLE>
    </body>
    </html>

    The fastest, but crudest and ugliest.
    <cfoutput query="GetCompanies">
    <tr #IIF(GetCompanies.CurrentRow MOD
    2,DE(''),DE('backgroundColor="##999"'))#>
    kellyhondalovesmusic wrote:
    > Hello
    > i have this query to html report
    > do you know how to make every other row grey in the out
    pu of the query.
    > ??
    >
    >
    > and where do i put it in this code below?
    >
    >
    >
    > thanks in advance
    >
    >
    >
    > <cfquery name="GetCompanies"
    > datasource="#Request.MainDSN#">
    > SELECT
    > CompanyID,
    > CompanyName,
    > Address,
    > City,
    > State,
    > ZipCode,
    > Comments
    > FROM
    > Company
    > ORDER BY
    > CompanyName ASC
    > </cfquery>
    >
    > <html>
    > <head>
    > <title>ColdFusion MX Bible</title>
    > <link rel="stylesheet" href="styles.css">
    > </head>
    >
    > <body>
    >
    > <h1>Company List</h1>
    >
    > <TABLE width=100% align="left" border="4"
    rules="all">
    > <tr>
    >
    > <td>
    ID</td>
    > <td>
    Name</td>
    > <td>
    Address</td>
    > <td>
    City</td>
    > <td>
    State</td>
    > <td>
    ZIP Code</td>
    > <td> </td>
    > </tr>
    > <cfoutput query="GetCompanies">
    > <tr>
    >
    > <td>#CompanyID#</td>
    > <td>#CompanyName#</td>
    > <td>#Address#</td>
    > <td>#City#</td>
    > <td>#State#</td>
    > <td>#ZipCode#</td>
    > <td>
    > <a
    href="EmployeeList.cfm?CompanyID=#CompanyID#">Employees</a>
    > <a href="CompanyAddForm.cfm">Add</a>
    > <a
    href="CompanyEditForm.cfm?CompanyID=#CompanyID#">Edit</a>
    > <a
    href="CompanyDeleteForm.cfm?CompanyID=#CompanyID#">Delete</a>
    > </td>
    > </tr>
    > </cfoutput>
    > </TABLE>
    >
    > </body>
    > </html>
    >
    >

  • PHP Image Gallery with Images placed every other paragraph

    Currently I have multiple images that where uploaded to the details page of Post 1. Every other paragraph I have an image displayed. With say 5 images.
    What I would like is that the user can click on the image and open up a gallery (on the same page, like Lightbox Gallery) and view through the other 4 images related to Post 1, as these images may not be full resolution on the details page.
    If I understand correctly, Lightbox makes a small thumbnail preview of the images, which I don't want, and lists them like a Gallery (Next to each other). Can anyone direct me on the best way to accomplish this?
    Thanks,
    Riley

    Sorry for the confusion, I didn't mean lightbox actually created the thumbnails, but it produces them similar to the link you provided which I don't want. My image uploader does create thumbnail images, but only one per new post.
    My format is similar to this:
    POST 1
    Text Paragraph1 (Image1 )
    Text Paragraph1 (               )
    Text Paragraph1 (               )
    Text Paragraph1 (               )
    (Image2) Text Paragraph2
    (               ) Text Paragraph2
    (               ) Text Paragraph2
    (               ) Text Paragraph2
    Now what I would like is that they can click on the picture and it opens up the image at say 600px X 600px resolution, with the next/prev buttons so they can browse through only the picutres on this page.
    I have been trying to find an example but seems that some take you to a different page of just the image you clicked on, or a new page with the gallery.
    I like how the lightbox gallery opens up on the same page, that way you close out of it and can continue reading. But I want to be able to have the images placed in different positions on the page, and not in a row like with a Gallery.
    I hope I help clarified what I am trying to do.

  • How to display images and information

    how to display images and information(e.g. like questions) on a jsp page that stored in a database

    Look As far as i can see....
    Utlimately every file could be expressed as a bytes buffer.
    so say if you have a bean called Choice Bean which is expressed as
    public class ChoiceBean{
       private String choiceid;
       private String choicedesc;
       private byte image[];
       public void setChoiceId(String choiceid){
              this.choiceid = choiceid;
        public String getChoiceId(){
               return this.choiceid;
          public void setChoiceDesc(String choicedesc){
               this.choicedesc = choicedesc;
           public String getChoiceDesc(){
               return this.choicedesc;
           public void setImage(byte image[]){
                  this.image = image;
             public byte[] getImage(){
                  return this.image;
    }QuestionList.java:
    ===============
    public class QuestionList{
         private List<ChoiceBean> choicelist;
          /*Other member variable declarations*/
           public  List<ChoiceBean> getChoiceList(){
                    /*Custom code where you may build the list by querying the DA layer*/
                     return this.choicelist;
         public int search(String choiceid){
                 int index = -1;
                 for(int i =0 ; i < this.choicelist.size() ; i++){
                        ChoiceBean cb = this.choicelist.get(i);
                         if(cb.getChoiceId().equals(choiceid)){
                                index = i;
                                break;
                 return index;
        /* Other member method declarations */
    }and you are retreving List<ChoiceBean> from DB using your query & have created a session attribute / <jsp:useBean> named ChoiceList
    NOTE: sometimes your application server can go out of bounds as you are consuming a lot of memory by creating an arraylist object.
    use the following methodology to display images & choices
    sample.jsp:
    =========
    <jsp:useBean id="QuestionList"  class="com.qpa.dao.QuestionList" scope="session"/>
    <TABLE>
    <%
    /* QuestionList.getChoiceList() is a method which fetches data from the DB & returns it in form of  List<ChoiceBean> */
    List<ChoiceBean> choicelist = QuestionList.getChoiceList();
    for(int i =0 ; i < choicelist.size() ; i++){
    %>
    <TR>
    <TD><%!=choicelist.get(i).getChoiceId()%></TD>
    <!-- calling servlet which renders an images in JPG format based upon given choiceid(unique field) -->
    <TD><IMAGE src="ImageServlet?choiceid=<%!=choicelist.get(i).getChoiceId()%>"/> </TD>
    <TD><%!=choicelist.get(i).getChoiceDesc()%></TD>
    </TR>
    <%
    %>
    </TABLE>
    <%
        session.remove("QuestionList");
    %>
    NOTE: usage of JSTL or any other custom built tag-libraries makes life more simpler in the following case
    ImageServlet.java:
    ===============
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            byte buffer[] = null;
            HttpSession session = request.getSession(false);
            /*getting the QuestionList from the session*/
            QuestionList ql = null;
            String choiceid = new String("");
            try{
                 choiceid = request.getParameter("choiceid");
                 /*getting the QuestionList from the session*/
                ql = (QuestionList)  session.getAttribute("QuestionList");
            } catch(Exception exp){
            if(choiceid.equals("") == false &&  ql != null ){
                List<ChoiceBean> clist = QuestionList.getChoiceList();           
                   assuming that you have created a serach method which searches the entire choice list and would give you
                   the index of that object which is being refered by unique choiceid and returns -1 if not found
                int index =  QuestionList.search(choiceid);
                if(index != -1){
                   ChoiceBean cb = clist.get(index);
                   buffer = cb.getImage();
            if(buffer != null){
                 // assuming that we have stored images in JPEG format only
                 JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new ByteArrayInputStream(buffer));
                 BufferedImage image =decoder.decodeAsBufferedImage();
                 response.setContentType("image/jpeg");
                 // Send back image
                 ServletOutputStream sos = response.getOutputStream();
                 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
                 encoder.encode(image);
            } else {
               response.setContentType("text/html");
               response.getWriter().println("<b>Image data not found</b>");              
    }However,i still feel there are few loopholes with this approach where Application Server can eat up a lot of heap space which may result in outofmemorybound exception.
    Hope this might help :)
    REGARDS,
    RaHuL

  • How to display URL images and URL link (html) from Smartforms?

    Hi Gurus,
    I'm having difficulty on how to display targeted URL images and URL link from the smartforms, after i sending it out as html mail. The mail i sent just can be preview as a plain text, which can't execute the html code that i put inside the smartforms itself. I follow a few step from this very useful blog.. Hopefully, you guys can give me some solutions or ideas on this.
    /people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp -thanks to Pavan for his useful blog.
    My code is like this..
    <--- Start Code.
    FORM call_smartforms.
      DATA : lv_subject TYPE so_obj_des,
             lc_true(1) VALUE 'X',
             lw_control_parameters TYPE ssfctrlop,
             lw_output_options TYPE ssfcompop,
             lc_graphics(8) VALUE 'GRAPHICS',
             lw_xsfparam_line TYPE ssfxsfp,
             lc_extract(7) VALUE 'EXTRACT',
             lc_graphics_directory(18) VALUE 'GRAPHICS-DIRECTORY',
             lc_mygraphics(11) VALUE 'mygraphics/',
             lc_content_id(10) VALUE 'CONTENT-ID',
             lc_enable(6) VALUE 'ENABLE',
             lw_job_output_info TYPE ssfcrescl,
             lw_html_data TYPE trfresult,
             lw_graphics TYPE ssf_xsf_gr,
             lt_graphics TYPE tsf_xsf_gr,
             lv_html_xstr TYPE xstring,
             lw_html_raw LIKE LINE OF lw_html_data-content,
             lv_incode TYPE tcp00-cpcodepage VALUE '4110',
             lv_html_str TYPE string,
             lv_html_len TYPE i,
             lc_utf8(5) VALUE 'utf-8',
             lc_latin1(6) VALUE 'latin1',
             lv_offset TYPE i,
             lv_length TYPE i,
             lv_diff TYPE i,
             lt_soli TYPE soli_tab,
             lw_soli TYPE soli,
             lc_mime_helper TYPE REF TO cl_gbt_multirelated_service,
             lv_name TYPE mime_text VALUE 'sapwebform.htm',
             lv_xstr TYPE xstring,
             lw_raw TYPE bapiconten,
             lt_solix TYPE solix_tab,
             lw_solix TYPE solix,
             lv_filename TYPE string,
             lv_content_id TYPE string,
             lv_content_type TYPE w3conttype,
             lv_obj_len TYPE so_obj_len,
             lv_bmp TYPE so_fileext VALUE 'BMP',
             lv_description TYPE so_obj_des VALUE 'Graphic in BMP format',
             lc_doc_bcs TYPE REF TO cl_document_bcs,
             lc_bcs TYPE REF TO cl_bcs,
             lc_send_exception TYPE REF TO cx_root,
             lw_adsmtp TYPE lty_adsmtp,
             lv_mail_address TYPE ad_smtpadr,
             lc_recipient TYPE REF TO if_recipient_bcs,
             lc_send_request TYPE REF TO cl_bcs,
             lv_sent_to_all TYPE os_boolean.
      DATA : v_language TYPE sflangu VALUE 'E',
             v_e_devtype TYPE rspoptype.
      v_form_name = 'ZTEST_EMAIL'.
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = v_form_name
        IMPORTING
          fm_name            = v_namef
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
    starting here. ***
    Set title for the output
      lv_subject = 'Smartforms.'.
    Set control parameters to "no dialog"
      lw_control_parameters-no_dialog = lc_true.
    IF lw_service_subject-code = lc_fm1.
    *--- To get output device type
      CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
        EXPORTING
          i_language    = v_language
          i_application = 'SAPDEFAULT'
        IMPORTING
          e_devtype     = v_e_devtype.
      lw_output_options-tdprinter = v_e_devtype.
      lw_control_parameters-getotf = 'X'.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
    Set output options
      lw_output_options-xsf        = lc_true.
      lw_output_options-xsfcmode   = lc_true.
      lw_output_options-xsfoutmode = 'A'.
      lw_output_options-xsfoutdev  = space.
      lw_output_options-xsfformat  = lc_true.
      lw_xsfparam_line-name  = lc_graphics.
      lw_xsfparam_line-value = lc_extract.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
      lw_xsfparam_line-name  = lc_graphics_directory.
      lw_xsfparam_line-value = lc_mygraphics.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
      lw_xsfparam_line-name  = lc_content_id.
      lw_xsfparam_line-value = lc_enable.
      APPEND lw_xsfparam_line TO lw_output_options-xsfpars.
    Get the smartform content
      CALL FUNCTION v_namef
        EXPORTING
          control_parameters   = lw_control_parameters
          output_options       = lw_output_options
    *pass other application specific parameters (eg order number, items ).
      IMPORTING
          job_output_info    = lw_job_output_info
      TABLES
          tt_tabh              = tt_tabh
          tt_tabb              = tt_tabb
          tt_tabf              = tt_tabf
      EXCEPTIONS
          formatting_error = 1
          internal_error   = 2
          send_error       = 3
          user_canceled    = 4
          OTHERS           = 5.
      IF sy-subrc = 0.
       break mhusin.
      ENDIF.
      lw_html_data  = lw_job_output_info-xmloutput-trfresult.
      lt_graphics[] = lw_job_output_info-xmloutput-xsfgr[].
      CLEAR lv_html_xstr.
      LOOP AT lw_html_data-content INTO lw_html_raw.
        CONCATENATE lv_html_xstr lw_html_raw INTO lv_html_xstr IN BYTE MODE.
      ENDLOOP.
      lv_html_xstr = lv_html_xstr(lw_html_data-length).
      CALL FUNCTION 'SCP_TRANSLATE_CHARS'
        EXPORTING
          inbuff       = lv_html_xstr
          incode       = lv_incode
          csubst       = lc_true
          substc_space = lc_true
        IMPORTING
          outbuff      = lv_html_str
          outused      = lv_html_len
        EXCEPTIONS
          OTHERS       = 1.
    *HACK THE HTML CODE GENERATED BY SMARTFORM TO MAKE THE
    *EXTERNAL IMAGES APPEAR AS <IMG> TAG IN HTML
      REPLACE ALL OCCURRENCES OF '<IMG' IN lv_html_str WITH '<IMG' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '/>' IN lv_html_str WITH '/>' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '</A>' IN lv_html_str WITH '' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '<' IN lv_html_str WITH '<' IGNORING CASE.
      REPLACE ALL OCCURRENCES OF '>' IN lv_html_str WITH '>' IGNORING CASE.
    CALL METHOD html_control - >load_mime_object
       EXPORTING
         object_id  = 'ZWN'
         object_url = 'ZWN.GIF'
       EXCEPTIONS
         OTHERS     = 1.
      REPLACE ALL OCCURRENCES OF lc_utf8 IN lv_html_str WITH lc_latin1.
    REPLACE ALL OCCURRENCES OF lc_utf8 IN lv_html_str WITH 'iso-8859-1'.
       break mhusin.
      lv_html_len = STRLEN( lv_html_str ).
      lv_offset = 0.
      lv_length = 255.
      WHILE lv_offset < lv_html_len.
        lv_diff = lv_html_len - lv_offset.
        IF lv_diff > lv_length.
          lw_soli-line = lv_html_str+lv_offset(lv_length).
        ELSE.
          lw_soli-line = lv_html_str+lv_offset(lv_diff).
        ENDIF.
        APPEND lw_soli TO lt_soli.
        ADD lv_length TO lv_offset.
      ENDWHILE.
      CREATE OBJECT lc_mime_helper.
      CALL METHOD lc_mime_helper->set_main_html
        EXPORTING
          content     = lt_soli
          filename    = lv_name
          description = lv_subject.
      LOOP AT lt_graphics INTO lw_graphics.
        CLEAR lv_xstr.
        LOOP AT lw_graphics-content INTO lw_raw.
          CONCATENATE lv_xstr lw_raw-line INTO lv_xstr IN BYTE MODE.
        ENDLOOP.
        lv_xstr = lv_xstr(lw_graphics-length).
        lv_offset = 0.
        lv_length = 255.
        CLEAR lt_solix[].
        WHILE lv_offset < lw_graphics-length.
          lv_diff = lw_graphics-length - lv_offset.
          IF lv_diff > lv_length.
            lw_solix-line = lv_xstr+lv_offset(lv_length).
          ELSE.
            lw_solix-line = lv_xstr+lv_offset(lv_diff).
          ENDIF.
          APPEND lw_solix TO lt_solix.
          ADD lv_length TO lv_offset.
        ENDWHILE.
        CONCATENATE lc_mygraphics lw_graphics-graphics text-001 INTO lv_filename.
        CONCATENATE lc_mygraphics lw_graphics-graphics text-001 INTO lv_content_id.
        lv_content_type = lw_graphics-httptype.
        lv_obj_len      = lw_graphics-length.
    *Add images to the email
        CALL METHOD lc_mime_helper->add_binary_part
          EXPORTING
            content      = lt_solix
            filename     = lv_filename
            extension    = lv_bmp
            description  = lv_description
            content_type = lv_content_type
            length       = lv_obj_len
            content_id   = lv_content_id.
      ENDLOOP.
      TRY.
          lv_subject = lv_subject.
          lc_doc_bcs = cl_document_bcs=>create_from_multirelated(
                   i_subject          = lv_subject
                   i_multirel_service = lc_mime_helper ).
        CATCH cx_document_bcs INTO lc_send_exception.
        CATCH cx_bcom_mime INTO lc_send_exception.
        CATCH cx_gbt_mime INTO lc_send_exception.
      ENDTRY.
    Create send request
      TRY.
          lc_bcs = cl_bcs=>create_persistent( ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
      TRY.
          lc_bcs->set_document( i_document = lc_doc_bcs ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
    Set-up email receiver
      lv_mail_address = '[email protected]'.
    TRANSLATE lv_mail_address TO UPPER CASE.
      TRY.
          lc_recipient = cl_cam_address_bcs=>create_internet_address(
              i_address_string = lv_mail_address ).
        CATCH cx_address_bcs INTO lc_send_exception.
      ENDTRY.
      TRY.
          lc_bcs->add_recipient( i_recipient = lc_recipient ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
    Send smartforms as HTML email
      TRY.
          lc_bcs->send( ).
        CATCH cx_send_req_bcs INTO lc_send_exception.
      ENDTRY.
      COMMIT WORK.
      WRITE:/ 'Mail sent'.
    ENDFORM.                    "call_smartforms
    End Code --->
    Thanks and Regards.

    1- put your images in a directory under the web app directory. Example: app/images/
    2- in your jsp, use: String file = application.getRealPath("/images/"); to get the images directory. See http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
    3- it's not the right forum to post this kind of question. Post them in the JSP/Servlet JSTL forum instead

Maybe you are looking for