C#如何将500M的图片压缩

cszrydn 2011-10-21 05:12:48
在C#中价值几百兆的图片就会出现内存不足的问题,图片在图片查看器中没有问题,为什么在bitmap、picturebox中都会内存溢出。怎样才能用C#写一个加载并显示500M左右的图片呢?能压缩就更好了。谁能帮帮忙啊,不胜感激!
...全文
207 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzxap 2011-10-21
  • 打赏
  • 举报
回复
写个循环 截取图片某个矩形,然后压缩在另一个大的矩形上画截取到的部分。直到截取完毕

主要利用://在指定位置画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
new System.Drawing.Rectangle(0, 0, image.Width, image.Height),
System.Drawing.GraphicsUnit.Pixel);
image:你的原图,
System.Drawing.Rectangle:位置与长宽,根据自己需要设置!
Icedmilk 2011-10-21
  • 打赏
  • 举报
回复
在硬盘上的图片一般是经过压缩的,如果要显示出来,必须要转换为无压缩的位图,所以就算提前用photo提前处理也没用。

这个问题必须将图片分块,只加载需要显示的区域,其他部分都放在硬盘
宝_爸 2011-10-21
  • 打赏
  • 举报
回复
zzxap 2011-10-21
  • 打赏
  • 举报
回复
将文件分割 读取 压缩 合并
宝_爸 2011-10-21
  • 打赏
  • 举报
回复
好像是挺麻烦的

We have a quite huge (~50MB) raster image in our map control.

The solution was to cut the main image into small pieces and load into a Image[,] array.

-------------------------------------
| pic00 | pic01 | | |
-------------------------------------
| pic10 | | | |
pic.png -> -------------------------------------
| | | | |
-------------------------------------
| | | | picnm |
-------------------------------------
You are able to draw this pieces with Graphics.DrawImage(..).

There is only big issue: if you need the whole picture on the screen, the drawing procedure can be slow. A good workaround to save a thumbnail and show that if needed.

来自
http://stackoverflow.com/questions/779395/how-to-handle-big-images-with-c-sharp
山东蓝鸟贵薪 2011-10-21
  • 打赏
  • 举报
回复
你想实现什么功能 
j_lei407 2011-10-21
  • 打赏
  • 举报
回复
为什么不换一个思路,把图片用photoshop压缩之后再进行加载呢……
kkbac 2011-10-21
  • 打赏
  • 举报
回复
帮顶.

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧