Display image as 'video' - java

I have an image file (for example img.png) which is updated (overwritten) every 20-30ms using a java program.
Now, I want the client to be able to 'watch' the image as it changing (it will look like a video streaming).
I used Javascript to update the image every 20-30ms but it is not that efficient as it consumes a lot of processing power. I also tried to use Ajax and jQuery.
Any suggestions on how to improve the performance? Can I use a player like jwPlayer or Flow Player? Should I use something different and more efficient?
Thanks.
PS. I have already implemented it using JApplet but I would like to avoid that solution.

You can update image by appending a random string at the end.
function update(){
$('#image').attr('src', $('#image').attr('src')+'?'+Math.random());
}
setTimeout("update()",150);

sounds like you just want a slideshow; there are super fast efficient slideshows in JavaScript, i'm lazy so here's the jQuery version:http://mathiasbynens.be/demo/slideshow if you're having performance issues using this, it's not because of the slideshow

You can update image using javascript timer (setTimeout) eg url

..it consumes a lot of processing power
Note that 'processing power' is not the same as 'bandwidth'.
To save bandwidth, it would make more sense to assemble the images into a video at the server side, and stream the video to the client. Video compression formats generally save a lot of bytes over a series of images, because they can compress images taking into account similar parts of different frames.

Related

Design Pattern for storing most requested images in a map object

I have a website that lets users generate an image. I then provide an embed link
which they can paste on their blog/website. The link conists of a simple html img
element which calls and then returns the image from my webapp to their website.
Currently, I'm reading the image from the file system and returning it via
the response outputstream.
My question is, is there a better more efficient way of doing this? I mostly would like
to keep the top 10 images in memory for faster access.
I currently have a singleton object that stores some data during app startup. My idea was to create a Map/List object and then store the image bytes in there. My images have unique names so that should make it a bit simpler.
I'd imagnie I'd need to store the image name, the last time accessesed, frequencey accessed and then kick out the images that were last accessed or have low times accessed.
I'd rather not re-invent the wheel if there is already a design pattern for this. Anyone ever implement something similar? Any general idea of what is the best way to implement this would be helpful.
I use Tomact 7, Java 7
What you're looking for is a caching library.
Check out:
Guava
Commons JCS
EHCache
Did you already take a look to the Guava-Libraries from Google? You can find a LoadingCache there, which maybe makes exactly what you want. Look at the CachesExplained Wiki page.

How to save a java-generated base64 image to server?

I've been struggling with this for the last few hours and can't seem to figure it out at all. To start I'll lay out what I'm trying to do.
I want to make it so that when you generate a craft idea on this page
http://craftspo.com/craft-idea-generator/
it saves an image of the idea on my server (so that I could then allow the user to pin it on Pinterest, share it on FB, and so on).
So far, I've managed to get it so that when they click the button, it uses html2canvas to snag a snapshot of the table. The problem is that image ends up being in base64, so it's pretty much unusable.
From what I've read, you can really only decode (and then save) base64 images to a server using PHP. And of course PHP is only called whenever you load the page but I'd rather not make them reload the page every time they generate a new idea. So is there anything else I can do? Even if it means doing something completely different. At this point, I just wanna make it happen so I can feel like I conquered the problem!
if I recall correctly base64 or image has no different,
just like the comment above
you could use it like :
<img src="data:image;base64,etc"/>
if you don't want the user to reload, you could use ajax to replace the src using javascript/jquery, you could just replace it with base64 image instead link to image.
if the image ain't that big, I myself would prefer to use base64,
you could also save the base64 string into database, if it could hold the length :D
and use it later on

java.awt -- when java outputs an image to my monitor (screen), where is the file that is output to the monitor card?

Suppose that I am drawing a set of images using java graphics objects. Suppose that I java is outputting these images to my monitor. Where is the file or files that are sent to the monitor card (the graphical representation files). How can I take this file and save it to disk, or how can I take this file and write it to an array, or how can I take these files and combine the results of their output (to the monitor) into a single file for saving? I don't want to use a screen shot feature, I want to be able to redirect (xor capture also) the output to the monitor to some sort of byte-stream. I note that monitors are much better than semaphores, when you are talking about display capabilities; I don't need a counter example.
I might not be asking the correct question. It might be that I want to capture the file while it is still in User Space, before it is put into 'Device Space'. I would like to try and capture the byte stream so that I can convert it to MPEG-4 format. I either need a streaming output from the MPEG-4 converter, coming from the streaming input, or else, I need to take static images at discrete times and convert the images.
What format will the output from User Space be in? What format will the Device Space output be in? Try to keep speculation to a minimum.
http://docs.oracle.com/javame/config/cdc/opt-pkgs/api/jsr927/index.html
I guess that Java has made a means of displaying AWT objects on a television screen. (Java TV).
In Java both the "user" and "device" data are handled via images and rasters. If you dig a little deeper in the source files you'll see that the SunGraphics2D, which is used for drawing behind the scenes, uses pipes (SunGraphics2D lines 154-159) which again uses Blits to transfer the graphics data onto an image (or a 2-dimensional screen). And both the graphics and pipes are programmed to do only this. So it is as MadProgrammer said - you need to render the graphics on an image to extract it. And this is basically as low-level as you get before the native implementations kick in.
This can be done in parallel with the normal paint-mechanisms running in Java. the thread MadProgrammer mentioned gives excellent examples really.

Loading raw HTML in Java/Android

I have written a couple of live wallpapers in recent weeks using local resources. Now a potential client wants me to make one that loads and displays the photos (usually between 3 and 10) from his daily news report posted online. The report file has a URL along the lines of http://example.com/dailytext/report.html which loads images along the lines of http://example.com/dailymedia/obama.jpg The references in report.html look like
img src="../dailymedia/obama.jpg" ...
Am I supposed to use a WebView to do this? That doesn't seem quite right, because I don't want to display the HTML. I would think that I want to throw the raw HTML into an array, parse the HTML looking for the instances of "img src...", reconstruct the full URLs, then load the bitmaps. I'm getting the impression this is more of a pure Java task than anything to do with Android's specialized classes, but I don't know. Any suggestions about "best practice?"
Unless I have misunderstood, this really isn't hard. You need to do the following:
Fetch the HTML, using either the native java networking api or something like HttpClient
Use a parser like Jericho or Dom4j to extract out the image links
Construct the absolute URLs, can be done with just java.net.URL
Fetch the images
You could also prefer using Jsoup
HTML Parser.

library for server side image resampling using java?

I want to create a serve resampled (downsized) version of images using jsp. The original images are stored in the database as blobs. I want to to create a jsp that serves a downsampled image with decent quality (not pixelated) as per the passed image width/height (e.g. getimage.jsp?imageid=xxxx&maxside=200) . Can you point me to a opensource api or code that I can call from the jsp page?
Java already contains libraries for image manipulation. It should be easy to resize an image and output it from a JSP.
This servlet looks like it does a very similar thing to what you want your JSP to do.
Is there anything wrong with the built-in Image.getScaledInstance(w, h, hints)? (*)
Use hints=Image.SCALE_SMOOTH to get non-horrible thumbnailing. Then use an ImageIO to convert to the required format for output.
*: well yes, there is something wrong with it, it's a bit slow, but really with all the other web overhead to worry about that's not likely to be much of an issue. It's also not the best quality for when upscaling images, where a drawImage with BICUBIC renderinghint is more suitable. But you're talking about downscaling only at the moment.
Be sure to check the sizes passed in so that you can't DoS your servlet by passing in enormous sizes causing a memory-eatingly-huge image to be created.

Categories