剪贴板图像返回大量内容 [英] Clipboard Image returns huge content

查看:87
本文介绍了剪贴板图像返回大量内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用剪贴板将图像复制粘贴到我的控件中.当我粘贴甚至很小的图像时,它也会返回非常大的

System.Drawing.Image oimage;
WebRequest request = WebRequest.Create(sPath); .GetResponse();
System.IO.Stream流; <=> stream = response.GetResponseStream();

System.Drawing.Image imageIn; FromStream(stream);
MemoryStream msTemp = new MemoryStream();
imageIn.Save(msTemp,System.Drawing.Imaging.ImageFormat.Jpeg);
MemoryStream objMemStreamByt =新MemoryStream(数据);
oimage = System.Drawing.Image.FromStream(objMemStreamByt);
Clipboard.Clear(); MyControl.Focus();
MyControl.Paste();
Clipboard.Clear();

hich是从剪贴板粘贴到mycontrol的,占用的空间非常大.有没有其他选择可以实现这一目标,从而导致体积更小?图像本身,但您正在运行的所有副本.您正在将图像流式传输到 imageIn 中,这意味着您的内存中有一个副本.然后,您创建将图像保存到的内存流.然后,将流转换为字节数组.接下来,您将创建另一个内存流(尽管这不会占用任何额外的内存).最后,您创建一个新图像 oimage .那是单个图像的4个副本.用 using 语句包装一次性物品,以确保正确清理内存.

我相信您还可以优化转换过程.将响应流直接传递到 Image.FromStream 以获取图像的一个副本.然后使用 Image.Save 将图像转换为新的流.最后,您可以使用 Image.FromStream 将流转换回图像,然后将其推送到剪贴板.所有图像和流对象都应使用 using 语句包装,以使它们能够自行清理.

Michael Taylor-2/17/09
Krishna Sarma

I suspect it isn't the image itself but all the copies you have running around.  You are streaming the image into imageIn which means you have one copy in memory.  You then create a memory stream that you save the image into.  Then you convert the stream into a byte array.  Next you create another memory stream (although this doesn't take up any extra memory).  Finally you create a new image oimage.  That's 4 copies of a single image.  Wrap your disposable objects in using statements to ensure the memory gets cleaned up properly. 

You can also optimize your conversion process I believe.  Pass the response stream directly to Image.FromStream to get one copy of the image.  Then use Image.Save to convert the image into a new stream.  Finally you can use Image.FromStream to convert the stream back to an image that you can then push to the clipboard.  All image and stream objects should be wrapped in a using statement to allow them to clean themselves up.

Michael Taylor - 2/17/09
http://p3net.mvps.org



这篇关于剪贴板图像返回大量内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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