I hava a Java/Grails app that needs to "read" the contents of a given URL to use it as an image, mostly to be dinamically resized.
My app already parses the url into HTML code using an implementation based on this post: http://www.roseindia.net/java/example/java/io/SourceViewer.shtml.
The class I built returns a String object that contains the HTML source code. Now I want to write this String into an object similar to a BufferedImage so I can display the captured URL into my new application.
any ideas, thanks in advance!
You can use a service like Bluga.net WebThumb and use Glen Smith's ThumbnailService to interface with it.
Or, if you really want to do this by yourself, you can use his Thumbnail Server (with an older version of the ThumbnailService), that he used to use before migrating to WebThumb ;)
Regards
You can create an Image object from a url :
URL url = new URL("http://url.to/your/image.jpg";
Image image = Toolkit.getDefaultToolkit().createImage(url)
If by
take a 'print screen' of the this site
you mean display in your app take a look at this : http://www.java-tips.org/java-se-tips/javax.swing/how-to-display-pages-for-a-web-site-in-your-applic.html
Related
I am trying to embed an image on a Freemarker ftl template to send as an email, I've based on this question Feemarker writing images to html, I did the exact same thing as this question said, but the email is being generated like this
What may be causing this error, and how to fix it?
My template looks like this
<img alt="My image" src="${imgAsBase64}" />
The image is a Chart, and I get the Base64 String, which I called imageBase64Str, via a Primefaces JavaScript function that generates the Base64 of the chart image, I pass it to the the bean and pass the parameter to the template like this
String encoded = imageBase64Str.split(",")[1];
byte[] decoded = Base64.decodeBase64(encoded);
String imgDataAsBase64 = new String(decoded);
String imgAsBase64 = "data:image/png;base64," + imgDataAsBase64;
emailParams.put("imgAsBase64", imgAsBase64);
String encoded = imageBase64Str.split(",")[1]; is suspicious. Looks like you are changing the base 64 string generated in some different way. Is the image actually a png or it's in another format? I think that if you remove that split and just do emailParams.put("imgAsBase64", imageBase64Str); it may work.
However you need to consider that this solution won't work for many email clients. According to this link https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/ Base64 embedded images are not supported on a few major email clients, web and standalone, including Gmail and Outlook. Given that they are the most common email clients you don't want to deliver a solution that doesn't work on them or most of your users are gonna be unhappy.
IMO your best bet is to host the images in a server and use fully qualified URLs in your freemarker template.
An alternative is using the attachment and reference them in the html source as explained here: https://stackoverflow.com/a/36870709/2546299 but it require changes on the way the emails are sent (need to add the attachments) so it may not be suitable for your case.
I want to play song in page when it opening. (I know It's a bad idea but I want to say Happy Birthday to my cousins :D ) for that I need to convert play framework routes to java.net.URL class. I tried these line of code but all of them gave me NULL pointer
URL url = app.getClass().getClassLoader().getResource(
"../../public/sounds/9-Baroon.wav");
URL url = app.getClass().getClassLoader().getResource(
controllers.routes.Assets.at("sounds/9-Baroon.wav").absoluteURL(request()));
URL url = app.getClass().getClassLoader().getResource(
controllers.routes.Assets.at("sounds/9-Baroon.wav");
how can I get that music file?
Some word
I'm stupid. I think I had to use controller for playing sound but this must done in views. I don't remove this question because anyone make that mistake find his/her mistake sooner.
It has nothing to do with Play Framework. You want to play sound on the webpage directly from HTML (or with some Javascript).
So you don't need Java for it (though your still can serve your .wav file from Play Framework as static asset).
Check these links: w3schools.com/html/html5_audio.asp or stackoverflow.com/a/13402388/972676.
I need a suggestion. Iam developing the face recognistion webservice (SOAP) in java, but front end is php application. User will send the image either by capturing using webcam or uploading the image. But i want this image and its detials as File Object in xml instead path from the server or database. Please suggest me how can i handle this or any other approaches.
Look at one of these:
$requestImageXML = '<img src="data:image/jpeg;base64,' . base64_encode(readfile($filePath)) . '"/>';
$requestImageString = base64_encode(readfile($filePath));
and use the string in a relevant way.
I'm writing an android magazine reader for a campus publication I work for. We use wordpress to publish our website, and I want to leverage the wordpress REST API to pull stories (posts) directly from the website, without publishers having to take any additional steps to publish posts on the app after publishing them on the site. I'll do this by getting JSON objects representing posts and deserializing them into POJOs of the Story class (defined in the android application), around which views will then be built dynamically.
I've just discovered the Wordpress REST API and am really excited because I think that the implementation as described above is going to be pretty simple. Are there any obvious roadblocks that I'm missing that might complicate things?
I know that the API responds with a "content" parameter that is a string containing the HTML code for the post, with references to included images/media in the appropriate places. How can I get Android to load that html and display it properly in a WebViewer?
If you don't want to parse the html and separately load images and other resources, simply use
loadDataWithBaseURL like so:
WebView storyView = (WebView) findViewById( .... );
String htmlToDisplay = ....;
storyView.loadDataWithBaseURL( "http://storysite.com/', htmlToDisplay, mimeType, encoding, "" );
The baseURL will be prepended to all relative partial URIs found in the document, so that the WebView can take care of loading all other assets for you.
i want to use pdfjet for a Google app engine project.
i downloaded the Java jar from the pPdfjet home page.
i followed an example given in a stack-overflow example and the examples given in the home page.
all the examples uses an empty constructor: PDF pdf=new PDF();. However when i try to use it,
it says that the constructor PDF() is undefined, further more all the method shown do not work:
pdf.wrap(): is undefined
pdf.save("Example_03.pdf"): is undefined
It looks like the examples on their web page are out of date. Look at the examples in the zip download instead. This simple example works for me:
OutputStream out = new FileOutputStream("test.pdf");
PDF pdf = new PDF(out);
Page page = new Page(pdf, Letter.PORTRAIT);
pdf.flush();
out.close();
Ok this is easy. Actually instead of taking from req.getOutputStream() directly create and instance of BytArrayOutputStream and use that.
For sending it just use out.toArray() as add it to the attacement part.