【问题标题】:Cropping Image with Cropper.js & Asp.net使用 Cropper.js 和 Asp.net 裁剪图像
【发布时间】:2019-01-18 20:36:37
【问题描述】:

试图获得裁剪的图像,但我一直得到图像的不正确部分。

我从cropper.js 得到这个,{left: 316, top: 50.5, width: 150, height: 150}

我在 vb 中将它传递给这个。

Public Shared Function CropImage(ByVal source As Image, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As Bitmap
    Dim crop As Rectangle = New Rectangle(x, y, width, height)
    Dim bmp = New Bitmap(crop.Width, crop.Height)

    Using gr = Graphics.FromImage(bmp)
        gr.DrawImage(source, New Rectangle(0, 0, bmp.Width, bmp.Height), crop, GraphicsUnit.Pixel)
    End Using

    Return bmp
End Function

但我最终只得到图像的左上角或右上角?有什么我想念的吗?我把它传给了 x,从cropper 传给了 y。我已经尝试了很多可能性,但似乎没有什么能给出我真正的裁剪结果。

【问题讨论】:

  • 程序(或多或少)正确。那么,1)当 X 和 Y 到达 CropImage 方法时,您是否验证了它们的值? 2) 裁剪的选区是相对于原始位图区域还是相对于在显示位图的容器内创建的选区?

标签: c# asp.net vb.net cropper


【解决方案1】:

我想通了……

问题是我正在查看原始照片的高度/宽度。当我裁剪它时,jscropper 正在查看一张较小的图片,因此当我取回 x 和 y 时坐标不正确。更正后,我发布的功能完美运行。

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 2016-05-06
    • 2018-12-12
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2012-04-18
    相关资源
    最近更新 更多