转换字节数组从动作脚本到图像中的Java和保存数组、字节、脚本、图像

2023-09-08 15:31:23 作者:#绯闻四起的男人

我是一个.NET开发人员,但我有这个问题是不相关的.NET 请记住这一点,即使我的问题听起来很琐碎。

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:

我们已经在浏览器中的SWF,它与一个Java扩展通信 它使用Smartfox服务器(用于MMO apllications)完成

We have an swf in the browser, which communicates with a java extension Its done using Smartfox Server(Used for MMO apllications)

这是我们抓住了屏幕的一部分作为动作脚本(3)字节数组的SWF。 而在Java中,我们调用一个函数的ByteArray转换成图像,然后将其保存。

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.

我们的Java开发人员遇到了错误

Our Java developer is encountering the error

java.lang.IllegalArgumentException异常

在Java函数执行时。

when the java function executes.

因此​​,基本上,我想知道是这样的:

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

如何接受从ActionScript中的Java对象类型字节数组? 请告诉我映射到字节数组中的ActionScript Java对象类型? 该转换部分是容易的,我敢说。

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.

更新:

在code在ActionScript中科

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);
}

第一个函数调用SmartFox扩展Java编写的。 扩展名是trialjava.js

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

Java的code,接受该函数是

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(ao.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);
    }
}

好像出现了一个小错配所检索的java对象。

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

现在的错误是不同的。

阵看的不是成功的。错误是:   java.io.NotSerializableException:   it.goto   andplay.smartfoxserver.lib.ActionscriptObject

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

问候, naveenj

Regards, naveenj

推荐答案

flash.utils.ByteArray的映射到Java的字节[] 键入

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