开发者

Convert Byte Array from Action Script to Image in Java and save it

I am a .NET Developer, but the question I am having is not related to .NET

Please keep this in mind even if my question sounds very trivial.

This is my question:

We have an swf in the browser, which communicates with a java extension

Its done using Smartfox Server(Used for MMO apllications)

From the swf we are grabbing a portion of the screen as "Byte Array" in action script(3). And in Java, we are calling a function that converts the ByteArray to Image and then saves it.

Our Java developer is encountering the error

java.lang.illegalArgumentException

when the java function executes.

So basically, what I would like to know is this:

How to accept the object type Byte Array from ActionScript in Java?

Whats Java object type that is mapped to Byte Array in ActionScript?

The conversion part is easy, I dare say.

Update:

The code in the ActionScript Section

public function savePhoto(uName:String, ba:ByteArray, descr:String):void{
    var obj:Object = {};
    obj.arr = ba;
    obj.desc = descr;
    sfsConnectobj.photoSectionSave(obj,"save");
}

public function photoSectionSave(targetObject:Object,type:String) {
    sfs.sendXtMessage("trialjava", "save", targetObject);
}

The first function calls the SmartFox Extension in Java. The extension name is "trialjava.js"

The Java Code that accepts the function is

public void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
{
    try {
        ActionscriptObject arr = ao.getObj("arr");
        String dirName="C:\\";
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos;
            oos = new ObjectOutputStream(bos);
            oos.writeObject(a开发者_运维问答o.getObj("arr"));
            oos.flush();
            oos.close();
            bos.close();
            byte [] data = bos.toByteArray();
            BufferedImage imag=ImageIO.read(new ByteArrayInputStream(data));
            ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));

    } 
    catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("Array reading not succesful. Error is: "+e);
    }
}

Seems like there was a small mismatch in retrieving the objects by java.

Now the error is different.

Array reading not succesful. Error is: java.io.NotSerializableException: it.goto andplay.smartfoxserver.lib.ActionscriptObject

Regards,

naveenj


flash.utils.ByteArray is mapped to Java's byte[] type.


I am not sure if this is an issue, but according to Flash security model, if SWF is loading media from any host/domain other that the one it was loaded, screen capture would result in error. Can you check the byte array you received? What is its size? And try to print its starting few values.


Byte array is not received directly. It comes inside an AS object. The real question here is how to get this byte array inside the ActionScript object to a Java byte array object.

I am the aforesaid Java developer and I am doing this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜