转换字节数组从动作脚本到图像中的Java和保存 [英] Convert Byte Array from Action Script to Image in Java and save it

查看:161
本文介绍了转换字节数组从动作脚本到图像中的Java和保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个.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.

这篇关于转换字节数组从动作脚本到图像中的Java和保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆