• 困扰我二天的 GDI+ 图像剪切已经解决。


    我要从一张照片剪切一部分图像下来,查了二天的资料没有解决。后来看到下面的地址跟我有一样的问题,解决方法也是从他那里来的。
    www.lemongtree.com/zh-cn/item.0000543.aspx

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

            
    Dim bit As New Bitmap(SourceImg)


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

            
    If SourceImgWidth > rec.Width Then
                rec.X 
    = 20 '(SourceImgWidth - rec.Width) / 2
            Else
                rec.X 
    = 0
                rec.Width 
    = SourceImg.Width
            
    End If

            
    If SourceImgHeight > rec.Height Then
                rec.Y 
    = 20 '(SourceImgHeight - rec.Height) / 2
            Else
                rec.Y 
    = 0
                rec.Height 
    = SourceImg.Height
            
    End If

            
    Try
                
    '这里就是把从上传过程中构造的bitmap克隆一份,并按定义好的矩形裁剪 
                bit.Clone(rec, PixelFormat.DontCare).Save(Response.OutputStream, ImageFormat.Jpeg)

            
    Catch ex As Exception
                Context.Response.Write(ex.Message)
                
    Exit Sub
            
    Finally
                bit.Dispose()
                SourceImg.Dispose()
            
    End Try
  • 相关阅读:
    查询记录时rs.previous()的使用
    Cocos2d-x中由sprite来驱动Box2D的body运动(用来制作平台游戏中多变的机关)
    vim经常使用命令总结
    微信公众号:码农的世界
    RHEL5 X86-64上安装Oracle 11gR2演示样例与总结
    JavaScript中获取当前项目的绝对路径
    thinkphp内置标签简单讲解
    function $(id) {}表示什么函数
    表单实例(判断两次密码是否一致)
    thinkphp模板继承
  • 原文地址:https://www.cnblogs.com/LCX/p/564789.html
Copyright © 2020-2023  润新知