C#.NET如何将动画GIF复制/粘贴到Windows剪贴板? [英] C# .NET How Can I copy/paste animated GIF to/from Windows Clipboard?

查看:199
本文介绍了C#.NET如何将动画GIF复制/粘贴到Windows剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C#.NET WinForms应用程序,我想将图像复制/粘贴到各个位置(网页,硬盘上的文件,应用程序中的图片框)到我的任何图片框应用程序。这是我到目前为止编写的代码...

 private void copyCMSMenuItem_Click(object sender,EventArgs e)
{
Clipboard.Clear ();
if(pbTSImage.Image!= null)
Clipboard.SetImage(pbTSImage.Image); //在这里,我正在从一个图片框调用"pbTSImage"中复制一个动画GIF。
}

private void pasteCMSMenuItem_Click(object sender,EventArgs e)
{
pbFSSImage.Image = Clipboard.GetImage(); //在这里,我从剪贴板粘贴图像。
}


我遇到的一个大问题是动画GIF在从一个图片框复制然后粘贴到另一个图片框时不会动画。可以/应该以这种方式处理动画GIF吗?我可以更好地将图像转换为字节数组
并在粘贴之前将它们转换回图像吗?我还尝试从硬盘复制图像并在运行时将其粘贴到图片框中,应用程序因空引用异常而崩溃。

解决方案





我遇到的一个大问题是动画GIF将会从一个图片框复制然后粘贴到另一个图片框中时没有动画。可以/应该以这种方式处理动画GIF吗? 



基本上,动画GIF由多个图像组成。将

复制到剪贴板时,实际上只复制了其中一个图像。因此,当您从剪贴板粘贴时,这是一张单张图片,它会被粘贴,因此没有动画。因此,b
$ b您是否阅读过这些主题?



如何从浏览器剪贴板API获取动画gif图像?

https://stackoverflow.com/questions/14934327/如何获取动画-gif-image-from-browser-clipboard-api
$


将.Gif图像从剪贴板放到PictureBox

https:// stackoverflow。 com / questions / 19756277 / put-gif-image-from-clipboard-to-picturebox



- Wayne


I'm writing a C# .NET WinForms app and I'd like to copy/paste images to/from various locations (web page, file on hard disk, picturebox in the app) to any picturebox in my app. Here's the code I've written so far...

        private void copyCMSMenuItem_Click(object sender, EventArgs e)
        {
            Clipboard.Clear();
            if (pbTSImage.Image != null)
                Clipboard.SetImage(pbTSImage.Image);     // Here, I'm copying an animated GIF from a picturebox call "pbTSImage."
        }

        private void pasteCMSMenuItem_Click(object sender, EventArgs e)
        {
            pbFSSImage.Image = Clipboard.GetImage();      // Here, I paste the image from the clipboard.
        }

The big problem I'm having is that animated GIFs will not animate when they've been copied from one picturebox and then pasted into another picturebox. Can/should animated GIFs be handled this way? Could I be better off converting the images to byte arrays and convert them back into images before pasting? I've also tried copying an image from my hard disk and pasting it into a picturebox at runtime and the app crashes with a null reference exception.

解决方案


The big problem I'm having is that animated GIFs will not animate when they've been copied from one picturebox and then pasted into another picturebox. Can/should animated GIFs be handled this way? 

Basically, an animated GIF consists of multiple images. When you copy
it to the clipboard, only one of those images is actually copied. So
when you paste from the clipboard it is that single image which gets
pasted, therefore no animation.

Have you read these threads?

how to get animated gif image from browser clipboard api?
https://stackoverflow.com/questions/14934327/how-to-get-animated-gif-image-from-browser-clipboard-api

Put .Gif Image from Clipboard to PictureBox
https://stackoverflow.com/questions/19756277/put-gif-image-from-clipboard-to-picturebox

- Wayne


这篇关于C#.NET如何将动画GIF复制/粘贴到Windows剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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