Javascript 获取从引导模式到java脚本的图像URL

Javascript 获取从引导模式到java脚本的图像URL,javascript,jquery,css,image,Javascript,Jquery,Css,Image,我正在修改一个图像并在模式中显示它,但我没有获得图像URL,因为此图像已在引导模式中修改并显示。 我想用JavaScript获取此图像的URL,以便上传到服务器 我已看到此链接,但不满意此解决方案: HTML代码: <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> &l

我正在修改一个图像并在模式中显示它,但我没有获得图像URL,因为此图像已在引导模式中修改并显示。 我想用JavaScript获取此图像的URL,以便上传到服务器

我已看到此链接,但不满意此解决方案:

HTML代码:

 <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
     <a class="btn btn-primary" id="upload" download="cropped.png" href="javascript:void(0);">Upload</a>
 </div>
我想将这个裁剪过的图像URL发送到服务器,但我无法获得 来自此图像的URL,因为每次剪切的图像都是新的,并且 是在重新加载图像丢失后在浏览器中临时保存的。 我将这个图像保存在变量b中,但它是bas64格式的,我们可以通过ajax直接发送到/sf/p/customizeText(url)

我们可以在变量b中分配result.toDataURL()并像ajax一样传入吗

                            data: b,

请给我一些实现此解决方案的想法。

裁剪的图像很可能是base64编码图像。您应该发布图像标记的HTML。您可以通过
attr()
获取图像资源

您必须通过js获取图像标签的
src
,并将其发送到服务器。然后您可以保存字符串并将其直接用作图像或解码它。我给你一个关于如何用PHP和Java实现这一点的小例子

PHP

//save your data into a variable - last part is the base64 encoded image
$encoded = "data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhE";
//decode the url, because we want to use normal charackters to use explode
$decoded = urldecode($encoded);
//explode at ',' - the last part should be the encoded image now
$exp = explode(',', $decoded);
//we just get the last element with array_pop
$base64 = array_pop($exp);
//decode the image and finally save it
$data = base64_decode($base64);
$file = 'data.png';
//make sure you are the owner and have the rights to write content
file_put_contents($file, $data);
Java

byte[] data = Base64.decodeBase64(crntImage);
try (OutputStream stream = new FileOutputStream("c:/decode/abc.bmp")) {
    stream.write(data);
}

为你的代码创建一个提琴。我不能创建提琴,因为代码太长并且依赖于许多文件。但是模态代码只有这一个。谢谢Adam这很好,但我正在使用java。我不能用java脚本将图像分配到文件中。我需要java脚本中此模式图像的url。您需要通过jQuery attr()获取源代码。您也可以将其写入文件,然后在服务器端使用java。
//save your data into a variable - last part is the base64 encoded image
$encoded = "data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhE";
//decode the url, because we want to use normal charackters to use explode
$decoded = urldecode($encoded);
//explode at ',' - the last part should be the encoded image now
$exp = explode(',', $decoded);
//we just get the last element with array_pop
$base64 = array_pop($exp);
//decode the image and finally save it
$data = base64_decode($base64);
$file = 'data.png';
//make sure you are the owner and have the rights to write content
file_put_contents($file, $data);
byte[] data = Base64.decodeBase64(crntImage);
try (OutputStream stream = new FileOutputStream("c:/decode/abc.bmp")) {
    stream.write(data);
}