Detect if .swf has transparent background - java

Is there a way to do this programmatically in PHP, Python or Java?
Use case:
User uploads .swf through an upload form.
Detect if it has a transparent background.
If it does, change it to something else, e.g. white.

This is very difficult to determine, because all SWFs are actually transparent (or they all can be) - it's just that they can contain shapes which cover the entire stage, which make them appear non-transparent.
To determine this programmatically, you'd need to loop over every shape in the SWF and look at it's bounds. However, that wont be enough since any shapes can be changed by ActionScript blocks and new shapes can be created at run time.
But really, making them transparent is the hard task. Since you want to make sure they're are non-transparent, you can just deal with this at display time - put a colored div behind the object or embed tag.

Probably impossible. I suggest a checkbox on the upload form "This flash app looks best with a transparent background".
Here is a flash app that has
- a transparent background to start
- a slider that lets you adjust the opacity
As you can see it would be impossible to say "transparent" or "opaque"

As far as I know you can't get the background alpha (transparency) of a swf file. what I would do if I were you would put the uploaded swf into a container swf (load the uploaded swf inside it) which only has a background color of your choice.
There used to be a php swf reader in this link. But I didn't see any alpha information in it aswell.

Flash is a bunch of compiled binary data. You Might be able to hunt down a third party library which can un-compile the flash file and get some of the data from the root movie scene, but it's a large stretch. As others have recommended, a checkbox during upload would be the best route to take.

I think you can read the .html where the .swf is placed and see if there is a parameter called "wmode" and is set to "transparent"
If that's the case you can get the html file and read it with Python, Java or PHP.
It's an ugly solution, but it's a solution.
PS: Sorry for my poor English.

The swf files are handled by plugins running inside or outside the browser. There is no way to tell if a certain flash has or hasn't transparent background... i guess you can assume that all of them are transparent..

Related

How to create a video from a series of images with transition

I want to create a video from a series of images and add a transition between the images (e.g., fade in and fade out). I’m looking for a Java solution and not a C++ one (FFmpeg or anything else).
I checked out JCodec and MediaCodec, but none of those support image transitions.
Have you already tried it with OpenCV for Java? OpenCV offers almost everything you need for such a task. To the transitions you would have to worry about then manually with image blending. But that can be solved with OpenCV too. Just take a look at the documentary
EDIT:
It looks like the Java API lacks the appropriate module that can encode a sequence of images. You can fade images in any case. Take a look at the tutorial. This means you would have to crossfade the images with OpenCV and then use another API (e.g. jcodec) to make a video from the images you create.

In Java, how to implement something like File Explorer?

I'm looking for a really simple widget: tree view on the left pane, folder contents on the right, switchable between icons, thumbnails, or detail view. Basically a functional (not pixel for pixel) emulation of Windows File Explorer, but within the Java app. How to do this using only built-in Java libraries? Or a very lightweight framework?
NOT A DUPLICATE
My question is different from the above and I now realize it's a little harder to explain than I initially expected. Two clarifications:
My question is not about a File Chooser. I'm asking about a File Explorer type of dialog. The difference is that a File Chooser is really focused on one task, choosing a file. A File Explorer is a little less focused, and lets the user browse around without a clear objective.
My question is not about native operating system UI / L&F emulation. At all. I'm asking about the basic capability to display the contents of the filesystem using icons and thumbnails. The style and borders etc are not part of my question.
EDIT
I'm looking for something like this
Notice how it's different from this (JFileChooser)
JFileChooser will do that if you are wanting something built in to Java.
https://docs.oracle.com/javase/7/docs/api/javax/swing/JFileChooser.html
If you are not using Swing but SWT (like Eclipse) you can use SWT FileDialog
You could use the AWT library to customly render the entirety of Explorer. Whilst the only hard part about this is correctly using layout managers to get components exactly where you want them and adding event listeners for each button, using AWT wouldn't make it look like Explorer on different operating systems because AWT uses the native system components.
You could check if the OS is not Windows and then use Swing if it isn't. In that case, you'd have to retexture every single used component such that its look and feel is the same as your targeted Windows version. Even if you did that, you'd still have to somehow change the JFrame's look and feel, which is possible using dark magic, but quite obscur. You can do this in a very quirky way, just setUndecorated(true) and manipulate the JFrame's boundaries until it lets you draw outside the JFrame, so that you can draw the Windows' decoration around it without resizing the Window. On top of that, you'd also have to check if it's maximised, as maximized windows don't quite look the same in Windows.
To cut things short, just use JFileChooser if you just want to allow the user to select one or multiple files. There isn't really any point in recreating Explorer, but if that's what you want to do, I'm not stopping you.

A JavaScript that clicks automatically over a flash object on document ready?

I got a flash document I CAN'T modify, that starts its animations only when pressing a button it has on it. I tried EVERY script I found on the internet but nothing worked. I need to simulate the click on that button so the flash animation can start! Is this possible?
If there are no APIs (which give you access to the elements),
you cannot interact with the Flash UI, because the Flash content has its own context, where JavaScript has no access to it.
You can try to decompile your flash file and get FLA-project of it. There it is possible to make required changes and create new swf.
There are many swf decompilers, but there is no 100% guarantee for successful decompilation (especially for big and complicated flash applications)

live Java GUI Builder like FireBug extension for HTML and CSS

I have been a Web Developer for more than 5 years and is now diving into Java as well. I have used NetBeans and its Drag & Drop feature. But due to habbit I like to code everything manually not by NetBean's Drag and Drop.
Everything is perfect but when it comes to put different components on different locations on a JPanel, it becomes really pain to know what co-ordinates for x and y to put components at.
When it's website developing in HTML and CSS, we have many tools like FireFox's FireBug extension etc which help us in adjusting CSS live.
Is there anything for Java as well so we can adjust our component live and then when we know x and y, we can make actual code in Java.
For example, I create a button and put in a jframe, when I run it, I can adjust it's location and then change my actual code.
I don't know it's either possible or not. But as there are Gurus so asking if they would be knowing of some tool.
Don't try to manually set x / y / size of components. Use layout managers and call pack() on your JFrame to size and place your components. Due to differences in screen size and resolution it is very difficult to have your GUI look nice on all systems using manual sizing and placement. Have a try with layout managers and come back with a specific question if you can't get the specific visual look you want.

Java - How to change cursor without Swing Component?

I have a Java application that run as a background service, i.e. no GUI. But when starting it, say through a batch script, I have some preparation works to be done at the very beginning of my program (something like communicate with server).
I want a busy cursor appear at this busy moment. Is it possible to do this without using any Swing component? Thanks for any suggestion or alternative approach.
I'd go for a console-based "progress bar". It's possible to use Swing but it would render your solution useless in a headless environment. Drawing progress bars with characters in terminal is quite a common practice.
You can either implement it yourself or use a ready class. Just take a look at github or bitbucket and you'll find something for sure.
A busy cursor could even be displayed as a caption with alternating last character (as simple as possible), with "frames" like these (rotating bar)
LOADING DATA /
LOADING DATA |
LOADING DATA \
LOADING DATA -
Implementing something like this wouldn't take much time. We're talking about minutes here.
If the only thing that prevents you from using Swing is an appearing window, you can change its appearance thanks to window translucency. This way you'd get an animated image overlaying your screen. It wouldn't work in a terminal though.
If you're able to use Java AWT (Abstract Window Toolkit) I beleive you can use the setCursor of Component class to change the cursor.
More on this : http://www.roseindia.net/java/example/java/awt/ChangeCursor.shtml

Categories