GDI+ 图像剪切

 Dim SourceImg As System.Drawing.Image = System.Drawing.Image.FromStream(Me.FileUpload1.PostedFile.InputStream)
None.gif        
Dim SourceImgWidth As Integer = SourceImg.Width '图片的原始Width 
None.gif
        Dim SourceImgHeight As Integer = SourceImg.Height '图片的原始Height 
None.gif

None.gif        
Dim bit As New Bitmap(SourceImg)
None.gif
None.gif
None.gif        
Dim rec As New Rectangle() '构造一个Rectangle类,一个矩形 
None.gif
        rec.Width = 100 'ConfigHelper.UserFaceWidth
None.gif
        rec.Height = 100 'ConfigHelper.UserFaceHeight
None.gif

None.gif        
If SourceImgWidth > rec.Width Then
None.gif            rec.X 
= 20 '(SourceImgWidth - rec.Width) / 2
None.gif
        Else
None.gif            rec.X 
= 0
None.gif            rec.Width 
= SourceImg.Width
None.gif        
End If
None.gif
None.gif        
If SourceImgHeight > rec.Height Then
None.gif            rec.Y 
= 20 '(SourceImgHeight - rec.Height) / 2
None.gif
        Else
None.gif            rec.Y 
= 0
None.gif            rec.Height 
= SourceImg.Height
None.gif        
End If
None.gif
None.gif        
Try
None.gif            
'这里就是把从上传过程中构造的bitmap克隆一份,并按定义好的矩形裁剪 
None.gif
            bit.Clone(rec, PixelFormat.DontCare).Save(Response.OutputStream, ImageFormat.Jpeg)
None.gif
None.gif        
Catch ex As Exception
None.gif            Context.Response.Write(ex.Message)
None.gif            
Exit Sub
None.gif        
Finally
None.gif            bit.Dispose()
None.gif            SourceImg.Dispose()
None.gif        
End Try

转载于:https://www.cnblogs.com/yanglin/archive/2007/06/28/799200.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值