cancel
Showing results for 
Search instead for 
Did you mean: 

Display JPG image in Webdynpro Java Application

Former Member
0 Kudos

Hi Everybody,

I want to display JPG images in my Web Dynpro Java Application. The images are stored  in a PC, but I dont want to open the file explorer and select the file using FileUpload UI. I need to write in my code a path like this: D:\100301.jpg and display the image.

I have used this code and it doesn't work, but if I choose the file with the FileUpload UI, the image is displayed succesfully.

      

String file = "D:\\100301.jpg";

    IWDResource resource = null; 

    try { 

  resource = WDResourceFactory.createResource(file.getBytes(),"100301",WDWebResourceType.JPG_IMAGE);

  wdContext.currentResourceElement().setImgResource(resource);

  wdContext.currentResourceElement().setImgURL(

  wdContext.currentResourceElement().getImgResource().getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));

    } catch (Exception e) { 

          e.printStackTrace(); 

    } 

The attribute ImgURL is bound to the image source property.

So, can someone help me with any suggestion in order to solve this issue?

Thanks!!!

Accepted Solutions (1)

Accepted Solutions (1)

vijay_kumar49
Active Contributor
0 Kudos

IWDResource resource = WDResourceFactory.createCachedResource(new ByteArrayInputStream(wdContext.currentFile_OutputElement().getChaE_String()),"JPG",WDWebResourceType.JPG_IMAGE,true);

IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.toString(),"Image Window");

window.show();

Please try the above code.  wdContext.currentFile_OutputElement().getX_String() is the XString attribute from the BAPI and the image is of type JPEG. if you want to open only JPEG then use this or use the resourcetype as Unknown.

Or

click on the  "Navigator" and find the respective project and navigate to the " comp\src\mimes\Components\<ur component name>" you can see all the images

weContext.currentcontextelment.setImage("Lotus.jpg");



Or


You can do it dynamically in wdDoModifyView()

IWDImage img=(IWDImage)view.getElement("<Image UI element ID>");

img.setHeight("200");

img.setWidth("400");


Kindly let me know if you need any more information.

Former Member
0 Kudos

Hi Vijay,

Thanks for your answer. But it is not working. The thing is that the images are stored in my pc, i tried to use an RFC for getting the xstring image and it works when it is executed from SAP but when i call the RFC from the portal (webdynpro), the RFC shows a Dump and cannot access the file. (Exception condition "NO_BATCH" raised., error key: RFC_ERROR_SYSTEM_FAILURE)

Do you know how can i get the xstring or byte array without bapi or RFC? only using webdynpro JAVA? and then use the code you told me before?

Thanks!!

vijay_kumar49
Active Contributor
0 Kudos

Please check this code. it should be useful    Example-1    and   Example-2

File file = new File("text.jpg");

FileInputStream fis = new FileInputStream(file);

byte[] buf = new byte[1024];

        try {

            for (int readNum; (readNum = fis.read(buf)) != -1;) {

                // Here populate the RFC table              

            }

        } catch (IOException ex) {

          

        }

Kindly let me know if you need any more information.

Former Member
0 Kudos

Hi Vijay,


The code works very good. I had to save the images in the MIME Repository, and then send the xtsring to webdynro.


Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

no way.

you are in dead end.