Editing SWF files using Transform SWF for Java from Flagstone - java

Has anyone successfully used the Transform SWF for Java library from [Flagstone Software][1]
[1]: http://www.flagstonesoftware.com/transform/index.html to edit an existing swf file. Mainly what I want to accomplish is load a swf file and replace images or texts dynamically. Thank you.

I know it is a little bit late, but google searchers will still land here :-) This code will color the first text span of all text elements to red.
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.zip.DataFormatException;
import com.flagstone.transform.Movie;
import com.flagstone.transform.MovieTag;
import com.flagstone.transform.datatype.Color;
import com.flagstone.transform.text.DefineText;
public class Flash {
public static void main(String args[]) throws MalformedURLException, DataFormatException, IOException {
Movie m = new Movie();
m.decodeFromFile(new File("C:\\tmp\\Movie.swf"));
for (MovieTag mt : m.getObjects()) {
System.out.println(mt.getClass() + " " + mt.toString());
if (mt instanceof DefineText) {
((DefineText) mt).getSpans().get(0).setColor(new Color(255, 0, 0));
}
}
m.encodeToFile(new File("C:\\tmp\\foo.swf"));
}
}

Yes, I am working on a desktop application that generates swf files. It is a little tricky but the samples in the Cookbook will help you a lot. Just go through the samples and you will find almost anything that you need.One thing is that, the developer stopped working on the framwork but it still works fine. Transform library only supports Flash 10 and Translate supports ActionScript 1.0. I had to change the ActionScript 2 and 3 code to AS1 for the framework to work which was for me to only replace the variable types when declaring variables.

Related

What class to import from JSoup library to be able to use the "getElement" classes

I am trying to find elements in an html page using Jsoup and I need to use the getElementsByAttributeValue class along with all the getElement classes.
The error showing in netbeans 8.0 is:
"cant find symbol"
so I suppose I haven't import the proper class in the head of the program. So what do I have to "import" to be able to use the getElement classes or if the problem is not in the "import" thing whats going on?
I can not use any of getElement by the way (is not only getElementsByAttributeValue) and I am using other classes of Jsoup like select with no problem.
getElementsByAttributeValue is the method of the class org.jsoup.nodes.Element so if you have an object of this class you should be able to access the method.
Ok, some how i solved the problem with this code:
`package sectors;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
public class TomaDatos {
public void nombre()throws IOException{
String ubic = "D:\\Varios\\Trabajo\\Bolsa\\sectorpp.docx";
FileInputStream file = new FileInputStream(new File(ubic));
XWPFDocument doc = new XWPFDocument(file);
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
}
}`
I really don´t know where exactly the problem was. The only important change was add XWPF after the "new" sentence here: XWPFWordExtractor ex = new XWPFWordExtractor(doc); But beleave me i tried that before and didnt work. Maybe is a problem with netbeans. I am sorry that i can not find the error, anyway, hope this work for someone....

Referencing Pictures from resource folder in a Jar

I can't help it but think I've missed just the Thread to answer my question but I've been looking for a long time now and can't seem to find the help I need.
My problem is quite simple:
I've created a game (or rather I'm in the process of it) and I'm trying to add sprites (png files for the enemies and such) to it. Loading them in the IDE works just fine but when I create a jar file and try to open it, it simply says "A Java Exception has occurred". Further investigation revealed the problem is that it can't find the files I told it to load.
Through the threads I've read I gathered this much:
It's either that I'm not loading the images properly, meaning that I don't use the proper code for it, or
my MANIFEST.mf does not contain a "Class-Path" (meaning that the arguments are blank, which in fact they are)
Finding other code didn't work out for me. People suggested to use a ClassLoader which I could't manage to get working. Trying it out gave me nullpointer exceptions.
Trying to look into the latter didn't do much help, because I couldn't find any helping information, or I'm just not understanding anything.
package platformer.resources;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
public class ImageLoader
{
static String spritePath = "src/platformer/resources/";
public static BufferedImage loadImage(String path)
{
BufferedImage img = null;
try{img= ImageIO.read(new File(spritePath+path));
}catch(IOException e){System.out.println("Couldn't load File: "+spritePath+path);}
return img;
}
public static BufferedImage flipImage(BufferedImage bufferedImage)
{
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-bufferedImage.getWidth(null), 0);
AffineTransformOp op = new AffineTransformOp(tx,
AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
bufferedImage = op.filter(bufferedImage, null);
return bufferedImage;
}
}
This is the code I used so far.
Other classes would use "loadImage" or "flipImage" and in the IDE it works fine but as a .jar it fails to find the .png.
For example the class "platformer/entities/walker.class" would try to open the "Idle.png". In order to do that it uses the "loadImage("/entities/enemy/walker/Idle.png")" method. Note that in the method the actual path would end up being "src/platformer/resources/entities/enemy/walker/Idle.png".
Again, I'm terribly sorry if this has already been answered but I appreciate your help nonetheless.
Michael
When your files are inside a jar they can only be taken out as a resource stream so you will want to use something like:
ImageLoader.class.getResourceAsStream("nameoffile").
This is because a jar is actually a zipped up directory structure and files are not really files they are hidden amongst a compressed zip formatting as binary.

Using/Reading FMOD (.fsb) Files in Java

Heyo Everyone. I am currently working on an Application which should play music files from an FMOD Database. It currently does it by Extracting the files (using a runtime and an external programm called "fsbextract.exe" (link)) as MP3 and then playing them. I am okay with this as it is, but i would now also love to edit/replace the files within the .fsb file. So my question is: Can i somehow directly acces the MP3 files in there without extracting them? I searched the internet for something like this but couldn't find any help.
For reference, here are some informations i can get from within fsbextract:
FileID is |FSB4> | Version is 4.0 | Number of Entries 7412
Global Flags:
0x40 | FMOD_FSB_SOURCE_MPEG_PADDED4 | MPEG frames are aligned to the nearest 4 bytes, 16 bytes for multichannel (Use Frame Verification option)
And from the first (index 0) file within the fsb file:
Format: MP3 (85)
Sample rate: 44100Hz
Channels: Mono
Duration: 01.541
Bitrate: 160,62 kbit/s
Bits/Sample 3.64
Sample Mode Flags [0x10000200]
0x200 | FSOUND_MPEG | Sample is stored in MPEG format
0x10000000 | FSOUND_MPEG_LAYER3 | Samples are stored in MPEG Layer 3 format
I hope someone knows more than me, but thanks in advance
Marenthyu
Jérôme Jouvie wrote a JNI wrapper for FMOD 4+, NativeFmodEx. If your FSB files are not encrypted I think you can use the API to extract streaming data from the FSB banks.
I tried to write my own wrapper as well but I didn't have the time to get past a simple proof of concept.
UPDATE: Sure. So basically what I did was to use JNAerator to wrap the native FMODex libraries and then targeting the resulting glue code to the BridJ runtime environment. That essentially allows you to invoke the native FMOD C library.
I'm not exactly sure if Jerome did something similar or if he created his own JNI stubs to achieve the same result. You'd have to check out and read his project's code.
But essentially, once you're able to make FMOD calls inside your application, you can use the API to do as you please. If you download the latest FMOD studio or FMODex SDK's from the FMOD web site you'll find a help .chm file which contains some documentation for the API.
You should also take a look at the examples in the SDK.
The following code is basically one example translated into Java, using the above mentioned strategy. The code isn't portable, robust or actually useful for an application. It really needs cleanup yet it still illustrates the point.
Like I said, you should be much better off using Jerome's SDK port.
Hope it helps.
package net.unsungstories.fmodex;
import net.unsungstories.fmodex.FmodexLibrary.FMOD_CHANNEL;
import net.unsungstories.fmodex.FmodexLibrary.FMOD_SOUND;
import net.unsungstories.fmodex.FmodexLibrary.FMOD_SYSTEM;
import org.apache.log4j.Logger;
import org.bridj.IntValuedEnum;
import org.bridj.Platform;
import org.bridj.Pointer;
import org.junit.Test;
import static org.bridj.Pointer.*;
import static net.unsungstories.fmodex.FmodexLibrary.*;
import static com.google.common.base.Throwables.*;
import static java.lang.String.format;
public class PlaySound {
private static final Logger log = Logger.getLogger(PlaySound.class);
#Test
public void playSound() {
log.info("Test started...");
String soundPath = "./src/test/resources/picus_get_to_finicular_music_0.fsb";
Platform.addEmbeddedLibraryResourceRoot("net/unsungstories/fmodex/");
IntValuedEnum<FMOD_RESULT> result;
Pointer<Pointer<FMOD_SYSTEM>> ppSystem = allocatePointer(FMOD_SYSTEM.class);
Pointer<Pointer<FMOD_SOUND>> ppSound1 = allocatePointer(FMOD_SOUND.class);
Pointer<Integer> pSubSounds = allocateInt();
Pointer<Pointer<FMOD_CHANNEL>> ppChannel = allocatePointer(FMOD_CHANNEL.class);
#SuppressWarnings("unchecked")
Pointer<FMOD_CREATESOUNDEXINFO> soundExInfo = Pointer.NULL;
Pointer<Byte> targetSoundPath = allocateBytes(soundPath.length() + 1);
targetSoundPath.setCString(soundPath);
result = FMOD_System_Create(ppSystem);
result = FMOD_System_Init(ppSystem.get(), 2, FmodexLibrary.FMOD_INIT_NORMAL, Pointer.NULL);
result = FMOD_System_CreateSound(ppSystem.get(), targetSoundPath, FMOD_HARDWARE, soundExInfo, ppSound1);
result = FMOD_Sound_GetNumSubSounds(ppSound1.get(), pSubSounds);
try {
Pointer<Integer> pChanelPlaying = allocateInt();
for (int k = 0; k < pSubSounds.get(); k++) {
Pointer<Pointer<FMOD_SOUND>> ppSubSound = allocatePointer(FMOD_SOUND.class);
result = FMOD_Sound_GetSubSound(ppSound1.get(), k, ppSubSound);
result = FMOD_System_PlaySound(ppSystem.get(), FMOD_CHANNELINDEX.FMOD_CHANNEL_FREE, ppSubSound.get(), 0, ppChannel);
FMOD_Channel_IsPlaying(ppChannel.get(), pChanelPlaying);
while (ppChannel.getBoolean()) {
log.info("Playing...");
Thread.sleep(1000);
FMOD_Channel_IsPlaying(ppChannel.get(), pChanelPlaying);
}
result = FMOD_Sound_Release(ppSubSound.get());
}
result = FMOD_System_Close(ppSystem.get());
result = FMOD_System_Release(ppSystem.get());
} catch (Exception e) {
log.error(getStackTraceAsString(getRootCause(e)));
}
log.info(format("Finished... %s", result));
}
}
Hope this helps.

OpenCV Feature Detection always returns nothing

Background:
I'm working on creating an OpenCV Java command line app to tease out some information from some particle streak images. In particular, I would like to know the dimensions of the smallest possible bounding box which will fit over each particle streak. First I have to find the particles, so I use Simple Blob feature detection.
Code:
package com.bostonwalker;
import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;
import java.util.List;
public class Main {
public static void main(String[] args)
{
System.loadLibrary("opencv_java247");
String sourcePath = "C:\\path_to_image\\05.png";
Mat srcImgMat = Highgui.imread(sourcePath);
if (srcImgMat == null)
{
System.out.println("Failed to load image at " + sourcePath);
return;
}
System.out.println("Loaded image at " + sourcePath);
MatOfKeyPoint matOfKeyPoints = new MatOfKeyPoint();
FeatureDetector blobDetector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
blobDetector.detect(srcImgMat, matOfKeyPoints);
System.out.println("Detected " + matOfKeyPoints.size()+ " blobs in the image");
List<KeyPoint> keyPoints = matOfKeyPoints.toList();
}
}
Error:
Unfortunately, the returned matOfKeyPoints is always empty (size always equals 1x0). I have scoured the web, but opencv for desktop Java is not an extremely popular library, and my problem doesn't seem to be that common. I have tried using other feature detector algorithms just to see if I can return any key points whatsoever (the answer is no).
My gut instinct tells me that the color channel scheme of the image is not supported by the Simple Blob algorithm. I have exported the .png files from Photoshop as 8 bits/channel Grayscale and 8 bits/channel RGB Color. It's hard to know what's actually going on in the Highgui.imread() call, and what the Mat data actually looks like.
Questions:
What is causing the call to detect to return an empty matOfKeyPoints?
Is there an easier way to do the image processing I want done?
More information:
OpenCV version 2.4.7
Image included below
RESOLVED:
Found the problem. Namely, a small typo in the source path. It looks like Highgui.imread() returns an empty Mat when an incorrect source path is used, instead of returning null like I assumed it would.

JavaCV: cvLoadImage returns null no matter what I pass it

I'm on OS X 10.7.1. I've downloaded the latest JavaCV binaries, and built OpenCV from a current subversion checkout. The cvLoadImage() function returns null, no matter what I pass it. I have verified that I am passing it a valid path to a valid jpg image. Other JavaCV functions seem to return reasonable values, but since I can't load images, I can't really check.
I think I may have an error somewhere, but I'm not familiar with how JavaCV reports errors, so I can't check.
EDIT: I can verify that the overall JavaCV installation is valid and functioning, in that if I use Java's ImageIO to load an image, it works and I can subsequently operate on the loaded image, and save an image out (again, through ImageIO). SSCE follows:
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.BufferedImage;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacpp.Loader;
class ImgLoadTest {
public static void main(String[] args) {
//comment out EITHER the BufferedImage bit OR the cvLoadImage portion.
//works
BufferedImage img = ImageIO.read(new File(args[0]));
IplImage origImg = IplImage.createFrom(img);
//returns null
//IplImage origImg = cvLoadImage(args[0]);
System.out.println("origImg is" + origImg);
}
}
Since I can make it work via ImageIO, I'm not overly concerned about this bug anymore, but solving it may be of use to others working with JavaCV.
OpenCV only works well with ASCII filenames. If you have i18n characters in the path, it may very well choke. Also, at the moment, JavaCV maps all String objects to UTF-8, and it does not seem like Mac OS X uses UTF-8 by default.
So, if i18n is important to your application, keep on using ImageIO...

Categories