I need a help regards copy image to clipboard in website. The image is dynamically created one.
I found two solutions
Solution 1 :
using System.Windows.Forms;
Bitmap bitmapImage ;
protected void buttonClipboard_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
MemoryStream memoryStream = new MemoryStream(imageByteArray); // Image byte array is the input
bitmapImage = (Bitmap)System.Drawing.Image.FromStream(memoryStream);
memoryStream.Flush();
memoryStream.Close();
Thread cbThread = new Thread(new ThreadStart(CopyToClipboard));
cbThread.ApartmentState = ApartmentState.STA;
cbThread.Start();
cbThread.Join();
}
[STAThread]
protected void CopyToClipboard()
{
if (bitmapImage != null)
{
//Clipboard.SetData(DataFormats.Bitmap, bitmapImage);
Clipboard.SetImage(bitmapImage);
}
}
This is working fine before publishing the website. After publishing this won't work in any website browsers because here STAThread used. Some websites said thread won't work in published website due to internal multi-thread handling in browsers.
Solution 2 :
<script type="text/javascript">
function CopyToClip() {
var imgControl = document.getElementById('imageContent');
imgControl.contentEditable = 'true';
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(imgControl);
controlRange.execCommand('Copy');
}
imgControl.contentEditable = 'false';
return true;
}
This java-script working fine for IE before & after publishing website. But it is not working in Chrome & Mozilla in any situation.
I need one solution for Mozilla & Chrome.
Please suggest any solution for this?