GDI+ Graphics.DrawImage 使用

最近项目中有个需求,需要将多张位图拼接成一张整体图,由于机器限制,需要考虑到处理时间。

我采用的处理方式是:按整体图的大小创建一块画布=>将每一张图贴在整体图的指定位置。

贴图的方法采用的 Graphics.DrawImage()中的两个重载:

1、Graphics.DrawImage(Image image,int x, int y);将位图按原始物理大小画在画布的指定位置。

   这里有个原始物理大小,并不是位图的像素,而是根据像素大小和图片的分辨率计算出来的尺寸(The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution.)。

2、Graphics.DrawImage(Image image,int x, int y,int width,int height);将位图按指定大小画在画布的指定位置。

方法一可以快速的处理(不需要进行缩放),方法二处理速度较慢(需要进行缩放操作)。

但是使用方法一时,如果贴入的图片分辨率和画布的分辨率不一致时,拼出来的图片并不是期待的结果。

查找资料,发现System.Drawing.Bitmap对象有个方法 SetResolution(int x,int y),可以直接设置图片的分辨率。

所以最终的处理方案为:按整体图的大小创建一块画布=>更改子图的分辨率=>将每一张图贴在整体图的指定位置。

posted @ 2018-01-22 10:31  Jazz_Law  阅读(4359)  评论(0编辑  收藏  举报
#RecentCommentsBlock li { margin: 0; width: 275px; } #RecentCommentsBlock li.recent_comment_body { border-radius: 0; margin: 0; } #RecentCommentsBlock li.recent_comment_title { border-radius: 5px 5px 0 0; margin: 3px 0 0; } #RecentCommentsBlock li.recent_comment_author { border-radius: 0 0 5px 5px; margin: 0; } .desc_img{ width:75px; max-width:75px; } #blog-calendar{ background:white; } /* comment */ div.commentform{ margin-bottom:100px; } #commentform_title { background: url("http://static.cnblogs.com/images/icon_addcomment.gif") no-repeat scroll 0 2px; color: #0078d8; font-size:14px; } div.commentform p{ margin-bottom:10px; } .comment_btn { height: 35px; width: 90px; background: none repeat scroll 0 0 #0078d8; border: 0 none; border-radius: 5px; color: white; cursor:pointer; } .comment_btn:hover{ background:#317ef3; } #commentbox_opt,#commentbox_opt + p { text-align:center; } #tbCommentBody{ width:100%; resize:none; } #tbCommentAuthor,#tbCommentBody{ border:1px solid #0078d8; } #tbCommentBody:hover{ border:1px solid #fca021; } #comments > h3 { background: none repeat scroll 0 0 #0078d8; border-radius: 3px; color: white; padding: 8px; border:0 none; font-size:14px; } #comments{ font-size: 13px; } #comments h4{ margin-top:10px; } #comments h4 span { color: #6c6351; font-size: 12px; } .comment_actions { border-bottom: 1px dashed #0078d8; display: block; padding-bottom: 10px; } .blog_comment_body { color: #111; font-size: 13px; margin-bottom: 10px; margin-top: 10px; } #comment_nav { font-size: 14px; margin-top: 10px; text-align: right; }