2017-01-03 98 views
-1

我想看到图像时,我下载到桌面上。我可以将div转换为图像的狗埠我似乎无法下载图像与狗形象的图像。为什么会发生?有人可以请帮我在这里找到一个解决方案是一个实时取景http://torcdesign.com/banana/div与图像和链接下载选定的图像

$(document).ready(function() { 
 
    $('#imajes').change(function() { 
 
    $('.subselector').hide(); 
 
    $('.smallimages').hide(); 
 
    $('#' + $(this).val()).show(); 
 
\t 
 
    }); 
 
    
 
    $('.smallimages').hide(); 
 
    var id = $(this).attr('id'); 
 
    var val = $(this).val(); 
 
\t 
 
\t 
 
$('#dog').on('change', function() { 
 
    
 
    $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none'); 
 

 

 
    $("#huntingdogimges").css('display', (this.value == 'huntingdog') ? 'block' : 'none'); 
 
    $("#germandogimges").css('display', (this.value == 'policedog') ? 'block' : 'none'); 
 
}); 
 

 
$('img').on('click', function() { 
 
    $('#fotos').append('<div class="imgdrag"><img class="modal-content" src="' + $(this).attr('src')+ '"/></div>'); $('.imgdrag').draggable(); 
 
$('#fotos').droppable(); 
 
\t   $('.modal-content').resizable(); 
 

 

 

 
}); 
 

 
    
 
    
 
}); 
 

 

 
var download = document.getElementById("download"), 
 
\t \t result = document.getElementById("previewImage"); 
 

 
function renderContent() { 
 
    html2canvas(document.getElementById("firstshirt"), { 
 
     allowTaint: true 
 
    }).then(function(canvas) { 
 
    \t \t result.appendChild(canvas); 
 
     download.style.display = "inline"; download.href = result.children[0].toDataURL(); 
 
    }); 
 
} 
 

 
function downloadImage() { 
 
\t \t 
 
} 
 

 
document.getElementById("btn-Preview-Image").onclick = renderContent; 
 
download.onclick = downloadImage
.container {background-color: transparent; 
 
    width: 300px; 
 
    height: 300px; 
 
    border: 2px solid red; 
 
    position: relative; 
 
overflow: hidden; 
 

 
/* Will stretch to specified width/height */ 
 
    background-size: 490px 500px; 
 
    background-repeat: no-repeat; 
 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<script type="text/javascript" 
 
\t src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script> 
 

 
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script> 
 
<script src="https://hongru.github.io/proj/canvas2image/canvas2image.js"></script> 
 

 
<script 
 
src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script> 
 
<link rel="stylesheet" 
 
href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
 
    <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
 
    <link rel="stylesheet" 
 
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<link href='https://fonts.googleapis.com/css?family=Philosopher' rel='stylesheet' type='text/css'> 
 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.js"></script> 
 
<script src="https://files.codepedia.info/uploads/iScripts/html2canvas.js"></script> 
 

 
<select id="imajes"> 
 
     <option value="">Choose Image</option> 
 
     
 
     <option value="dog">Dog</option> 
 
     
 
    </select> 
 

 
<select id="dog" name="subselector" class="subselector" style="display:none"> 
 
    <option value="">Choose an item</option> 
 
    <option value="bulldog">Bulldog</option> 
 
    <option value="huntingdog">Hunting Dog</option> 
 
    <option value="policedog">German Shepherd</option> 
 
</select> 
 
<div id="firstshirt" class="container" style="float:left;"><div id="fotos" ><img class="modal-content" id="imgdisplay" /></div></div> 
 
<input id="btn-Preview-Image" type="button" value="Preview"/><a id="download" download="my_image.png" href="#">Download image</a> 
 
<h3>result:</h3> 
 
<div> <div id="previewImage"> 
 
    </div><a id="download" download="my_image.png" href="#">Download image</a></div> 
 
    
 
    <div style='display:none;' id="bulldogimges" class="smallimages"> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif"> 
 
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif"> 
 
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif"> 
 
    <img src="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 

 
</div>

+0

您downloadImage()方法是空的实现。它不包含任何语句。 – Rajashekhar

回答

1

您可以检查更新的代码:

我已经更新下载图像按钮的代码。

$(document).ready(function() { 
 
    $('#imajes').change(function() { 
 
    $('.subselector').hide(); 
 
    $('.smallimages').hide(); 
 
    $('#' + $(this).val()).show(); 
 
\t 
 
    }); 
 
    
 
    $('.smallimages').hide(); 
 
    var id = $(this).attr('id'); 
 
    var val = $(this).val(); 
 
\t 
 
\t 
 
$('#dog').on('change', function() { 
 
    
 
    $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none'); 
 

 

 
    $("#huntingdogimges").css('display', (this.value == 'huntingdog') ? 'block' : 'none'); 
 
    $("#germandogimges").css('display', (this.value == 'policedog') ? 'block' : 'none'); 
 
}); 
 

 
$('img').on('click', function() { 
 
    $('#fotos').append('<div class="imgdrag"><img class="modal-content" src="' + $(this).attr('src')+ '"/></div>'); $('.imgdrag').draggable(); 
 
$('#fotos').droppable(); 
 
\t   $('.modal-content').resizable(); 
 

 

 
$(".download").attr("href",$(this).attr('src')); 
 
    $(".download").show(); 
 
}); 
 

 
    
 
    
 
}); 
 

 

 
var download = document.getElementById("download"), 
 
\t \t result = document.getElementById("previewImage"); 
 

 
function renderContent() { 
 
    html2canvas(document.getElementById("firstshirt"), { 
 
     allowTaint: true 
 
    }).then(function(canvas) { 
 
    \t \t result.appendChild(canvas); 
 
     download.style.display = "inline"; download.href = result.children[0].toDataURL(); 
 
    }); 
 
} 
 

 
function downloadImage() { 
 
\t \t 
 
} 
 

 
document.getElementById("btn-Preview-Image").onclick = renderContent; 
 
download.onclick = downloadImage
.container {background-color: transparent; 
 
    width: 300px; 
 
    height: 300px; 
 
    border: 2px solid red; 
 
    position: relative; 
 
overflow: hidden; 
 

 
/* Will stretch to specified width/height */ 
 
    background-size: 490px 500px; 
 
    background-repeat: no-repeat; 
 
} 
 

 
.download{ 
 
display:none; 
 

 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<script type="text/javascript" 
 
\t src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script> 
 

 
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script> 
 
<script src="https://hongru.github.io/proj/canvas2image/canvas2image.js"></script> 
 

 
<script 
 
src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script> 
 
<link rel="stylesheet" 
 
href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
 
    <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> 
 
    <link rel="stylesheet" 
 
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js"></script> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<link href='https://fonts.googleapis.com/css?family=Philosopher' rel='stylesheet' type='text/css'> 
 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<script src="https://rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.js"></script> 
 
<script src="https://files.codepedia.info/uploads/iScripts/html2canvas.js"></script> 
 

 
<select id="imajes"> 
 
     <option value="">Choose Image</option> 
 
     
 
     <option value="dog">Dog</option> 
 
     
 
    </select> 
 

 
<select id="dog" name="subselector" class="subselector" style="display:none"> 
 
    <option value="">Choose an item</option> 
 
    <option value="bulldog">Bulldog</option> 
 
    <option value="huntingdog">Hunting Dog</option> 
 
    <option value="policedog">German Shepherd</option> 
 
</select> 
 
<div id="firstshirt" class="container" style="float:left;"><div id="fotos" ><img class="modal-content" id="imgdisplay" /></div></div> 
 
<input id="btn-Preview-Image" type="button" value="Preview"/><a class="download" id="download" download="my_image.png" href="#">Download image</a> 
 
<h3>result:</h3> 
 
<div> <div id="previewImage"> 
 
    </div><a id="download" class="download" download="my_image.png" href="#">Download image</a></div> 
 
    
 
    <div style='display:none;' id="bulldogimges" class="smallimages"> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif"> 
 
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif"> 
 
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif"> 
 
    <img src="https://torcdesign.com/clipart/free-bulldog-clipart-031350.gif" alt="Smiley face" width="55" height="55"> 
 
    </div> 
 

 
</div>

+0

它的工作原理,但一旦我插入它与我的东西的其余部分我仍然得到一个空白img – xcalliber

+0

这里是一个URL,所以你可以看到即时通讯谈论非常抱歉http://stackoverflow.com/questions/41435701/converting-div -with-other-images-inside-into-image?noredirect = 1#comment70077430_41435701 – xcalliber

+0

你需要分配href来下载链接。上述问题处于搁置状态。所以我无法回答。 –