Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用Web服务保存图像_Java_Web Services_Web - Fatal编程技术网

在Java中使用Web服务保存图像

在Java中使用Web服务保存图像,java,web-services,web,Java,Web Services,Web,我有一个屏幕截图,它是通过将javascript代码转换成字符串(type)从浏览器中获得的。我需要一个Web服务,它可以读取这个字符串并在服务器端将其转换为图像 问题是: 我应该如何制作一个能够从浏览器中读取字符串并将其转换为图像到服务器端的web服务 下面显示了代码 package com.myfirst.wsServer; import java.io.FileOutputStream; import java.util.UUID; import javax.jws.WebService;

我有一个屏幕截图,它是通过将javascript代码转换成字符串(type)从浏览器中获得的。我需要一个Web服务,它可以读取这个字符串并在服务器端将其转换为图像

问题是:

我应该如何制作一个能够从浏览器中读取字符串并将其转换为图像到服务器端的web服务

下面显示了代码

package com.myfirst.wsServer;
import java.io.FileOutputStream;
import java.util.UUID;
import javax.jws.WebService;
import org.apache.commons.codec.binary.Base64;

@WebService
public class ConvertToImage {
/**
     * Convert input string image to image
     * @param imageDataString
     */

public static void StringToImage(String imageDataString){

    try {
        // Converting a Base64 String into Image byte array
        byte[] imageByteArray = decodeImage(imageDataString);

        // Write a image byte array into file system
        FileOutputStream imageOutFile = new FileOutputStream("D:\\" + getNewFileName() + ".png");

        imageOutFile.write(imageByteArray);

        imageOutFile.close();

        System.out.println("Image Successfully Manipulated!");
    } 
    catch (Exception e) {
        // TODO: handle exception
    }
}

/**
 * Encodes the byte array into base64 string
 *
 * @param imageByteArray - byte array
 * @return String 
 */
public static String encodeImage(byte[] imageByteArray) {
    return Base64.encodeBase64URLSafeString(imageByteArray);
}

/**
 * Decodes the base64 string into byte array
 *
 * @param imageDataString
 * @return byte array
 */
public static byte[] decodeImage(String imageDataString) {
    return Base64.decodeBase64(imageDataString);
}

/**
 * Generate uuid an convert to String
 * @return uuid.toString()
 */

public static String getNewFileName(){
    UUID uuid = UUID.randomUUID();

    return uuid.toString();
}
}
欢迎提出任何问题或建议 多谢各位


PS:如果您能帮助我并且对Javascript代码感兴趣,我可以与您分享。

但是您已经在这里的服务器上了。为什么要再次传输它?我不会再次传输它,只是使用web服务从客户端(浏览器)读取字符串