eclipse plugin: add image to browser - java

I have created an Eclipse plugin which displays a browser with a URL as follows:
browser.setBounds(0, 0, 100, 100);
browser.setUrl("https://www.stackoverflow.com/");
Also I am able to get the animated image from the bundle as follows:
Image image = ImageDescriptor.createFromURL(FileLocator.find(bundle, new Path("icons/sample.gif"), null)).createImage();
How could I add the Image to the browser on run time execution?

Since you're setting the Browser widget to display a URL, the widget will display the contents of that URL.
If you want to display your own content, you'll have to use the setText() method.
Perhaps you can create html that includes the URL you want in an IFRAME and compose the rest of the html with your own content?
As for the image, I'm sure there are ways to include the image in the constructed HTML ... or you can base64 encode the data and include it in the constructed HTML. See Can I embed a .png image into an html page?

Related

Glide not downloading image

I have array of object with some parameters.
One of the parameters is imageUrl.
I'm trying to download them with Glide library, and all of them is downloaded and shown on the RecyclerView.
But , one of them no appear.
Here is the image url that not shown.
https://www.imdb.com/title/tt0068646/mediaviewer/rm746868224
When I'm opening this url with my browser, the image appear.
Here is my code to show the all images.
Glide.with(getContext())
.load(mMoviesResponse.getImage())
.into(mIVMovieImage);
BTW,
others image has urls like this one and they are working good:
https://api.androidhive.info/json/movies/2.jpg
Because url you provided is not image's url. It is a web page(You see there is no extension like jpg, png etc. at the end of your url). Use this url instead: https://m.media-amazon.com/images/M/MV5BM2MyNjYxNmUtYTAwNi00MTYxLWJmNWYtYzZlODY3ZTk3OTFlXkEyXkFqcGdeQXVyNzkwMjQ5NzM#._V1_SY1000_CR0,0,704,1000_AL_.jpg
I got it via Right mouse click on image > copy image address.

Images are not showing in pdf created using velocity template

I create pdf using Velocity template, but i am not able to put images in pdf.
I am adding url into context object and accessing that object into eot.vm file, url is going proper but still images are not displaying in pdf.
Thanks & Regards,
Tushar
Make sure that URL you are passing is sending IMAGE as response not an full html page.
i was passing URL that was sending me a whole html page, so i was unable to see images.
But now its fixed.
Please visit below link:
https://answers.atlassian.com/questions/2907/how-to-access-image-generated-via-velocity-template-confluence

Java code to display an Image in Google App Engine

I have an image in the blobstore of my GAE . I need to retrieve it and make some trasformations and finally display it in my jsp page.
Currently I used,
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
blobstoreService.serve(blobKey, res);
This shows the picture but I want to retrieve it as an 'Image' type and resize it using the code below
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
Transform resize = ImagesServiceFactory.makeResize(200, 300);
Image newImage = imagesService.applyTransform(resize, oldImage);
byte[] newImageData = newImage.getImageData();
How will I display my 'newImage' in a jsp page? It would be very helpful if I could see an example code. I would also like to know if there is any way i can get the blob-key of the images I presently have in my blobviewer.
You should not process the image in the request for your JSP page.
You have to take two steps:
1.
Render a JSP page that contains an image tag like
<img src="mydomain.com/getImage?blob-key=123435"/>
2.
Have a separate servelt mapped to mydomain.com/getImage that outputs the image with the given id.
So all the code you presented above will go in the servlet that delivers the image and not in the JSP delivering code. And then the image can be delivered using the HTTPResponses OutputStream. And don't forget to set the correct content type and length for the response.

LWUIT HtmlComponent render local image

I want to render content that i have created locally using html component and put image in this html also by putting image in res folder in jar, i tried
<img src='images/down.png'></img>
<img src='res/images/down.png'></img>
<img src='./images/down.png'></img>
but nothing worked, any suggestion?
[EDIT]
here is my code, i have no idea how to implement DocumentRequestHandler that is why i used DefaultDocumentRequestHandler
DocumentRequestHandler handler = new DefaultDocumentRequestHandler();
HTMLComponent component = new HTMLComponent(handler);
component.getStyle().setBorder(Border.createLineBorder(1));
component.getSelectedStyle().setBorder(Border.createLineBorder(1));
component.setBodyText("<div><b>nirmal:</b>" +
"<img src='res://images/down.png' /></div>");
tried res://images/down.png but nor worked
my image is in res/images
You need to explain how you loaded the HTML, images are loaded relatively to the base URL so you need to define the base URL when creating the HTML (its implicitly detected when loading via URL).
If you created the HTML via setHTML(String) then you need to give absolute paths depending on your DocumentRequestHandler implementation e.g. res://myImage.png or file://myImage.png .

captcha image coming back a binary data? How to display this?

I am retrieving a captcha image from the Java based package "SimpleCaptcha"
On the front end I just put the following in my page and I get a captcha image:
<img src="stickyImg" />
I want to reload this captcha image onclick using javascript.
I tried:
$("#theclickhandler").click(function(){
$("#stickyImg").load('stickyImg', function(response){
$("#stickyImg").attr('src', response);
});
return false;
});
This gets the image but outputs something like this (greatly shortened obviously):
<img src="captcha image�PNG �ݚ��L�23U�݆�}$�J����Dy����IEND�B`� ">
That looks like raw, binary data to me. How do I get this to work?
The src attribute of an image tag specifies to the browser where the image to load is, not the content of the image. So you're stuffing the content of the image into the place where you want the location to be, and that's giving you garbage because it simply doesn't make sense.
So, to reload the image, you need to tell the browser that the address of the image has changed. It's not sufficient to simply rewrite the location in the image's src attribute to the same address -- that won't tell the browser to change anything. You can overcome this by stuffing some random data in the query string, say, the time of the request. Like #mikerobi suggests, you can just rewrite the src tag, here with the modification of putting a timestamp in the query string (which your servlet will almost surely ignore):
$('#stickyImg').attr('src', 'stickyImg?' + (new Date().getTime()));
You can't use that approach to load images, you need to set the image url attribute to the path of the image generator.
$('#stickImg').attr('src', 'path/to/image/generator');
I don't know how many browsers support it, but it's possible to base64 encode an image, prefix it with (depending on the image format) "data:image/png; base64,", and use that as a URI for the image.

Categories