Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:正方形图片伸缩成梯形图片

1楼
genggeng 发表于:2024/5/27 9:02:00
代码如下,在执行
' 应用梯形变换
        matrix.Shear(topCenter, bottomCenter, heightFactor, 0)
时报错。请问该如何解决?


Dim originalImage As Image = Image.FromFile(txt3 & "\" & t(zdw) & ".png")
    
    ' 创建一个新的Bitmap对象,用于存储转换后的梯形图片
    Dim width As Integer = originalImage.Width
    Dim height As Integer = originalImage.Height
    Dim newImage As New Bitmap(width, height)
    
    ' 使用Graphics对象来绘制图像
    Using g As Graphics = Graphics.FromImage(newImage)
        ' 创建一个Matrix对象来定义变换
        Dim matrix As New Matrix()
        
        ' 定义梯形的变换参数
            ' 这里假设我们想要一个顶部宽度比底部宽度小的梯形
        ' 需要根据实际需求调整参数
        Dim topWidth As Single = width * 0.8F
        Dim bottomWidth As Single = width
        Dim heightFactor As Single = 1F
        
        ' 计算梯形的顶部和底部中心点
        Dim topCenter As Single = topWidth / 2F
        Dim bottomCenter As Single = bottomWidth / 2F
        
        ' 应用梯形变换
        matrix.Shear(topCenter, bottomCenter, heightFactor, 0)
        
        ' 创建一个GraphicsPath对象来定义梯形的路径
        Dim path As New GraphicsPath()
        path.AddLine(topCenter, 0, topCenter, heightFactor * height)
        path.AddLine(topCenter, heightFactor * height, bottomCenter, height)
        path.AddLine(bottomCenter, height, bottomCenter + (bottomWidth - topWidth) / 2, heightFactor * height)
        path.AddLine(bottomCenter + (bottomWidth - topWidth) / 2, heightFactor * height, bottomCenter + (bottomWidth - topWidth), 0)
        path.CloseAllFigures()
        
        ' 将路径应用于Graphics对象
        g.SmoothingMode = SmoothingMode.AntiAlias
        g.InterpolationMode = InterpolationMode.HighQualityBicubic
        g.PixelOffsetMode = PixelOffsetMode.HighQuality
        g.DrawImage(originalImage, path)
        
        ' 显示转换后的梯形图片
        p3.Image = newImage
    End Using
    newImage.Save(txt3 & "\" & t(zdw) & "-tx.png")
图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看
2楼
有点蓝 发表于:2024/5/27 9:53:00
微软文档的里这个方法只有2个和4个参数,没有4个参数的

https://learn.microsoft.com/zh-cn/dotnet/api/system.drawing.drawing2d.matrix.shear?view=netframework-4.0&redirectedfrom=MSDN#System_Drawing_Drawing2D_Matrix_Shear_System_Single_System_Single_System_Drawing_Drawing2D_MatrixOrder_
共2 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02307 s, 2 queries.