Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 点,它是它自己的一个小矩形。您想捕获像素矩形右下角的新坐标表示。使用此方法似乎可以让我了解我所在的位置。它仍然在一般地区,但不完全是。 private static Rectangle MaintainAspectRatio(Image imgPhoto,_C#_Image Scaling - Fatal编程技术网

C# 点,它是它自己的一个小矩形。您想捕获像素矩形右下角的新坐标表示。使用此方法似乎可以让我了解我所在的位置。它仍然在一般地区,但不完全是。 private static Rectangle MaintainAspectRatio(Image imgPhoto,

C# 点,它是它自己的一个小矩形。您想捕获像素矩形右下角的新坐标表示。使用此方法似乎可以让我了解我所在的位置。它仍然在一般地区,但不完全是。 private static Rectangle MaintainAspectRatio(Image imgPhoto,,c#,image-scaling,C#,Image Scaling,点,它是它自己的一个小矩形。您想捕获像素矩形右下角的新坐标表示。使用此方法似乎可以让我了解我所在的位置。它仍然在一般地区,但不完全是。 private static Rectangle MaintainAspectRatio(Image imgPhoto, Rectangle thumbRect) { int sourceWidth = imgPhoto.Width; int sourceHeight = imgPhoto.Height; int sourceX = 0; int sou


点,它是它自己的一个小矩形。您想捕获像素矩形右下角的新坐标表示。使用此方法似乎可以让我了解我所在的位置。它仍然在一般地区,但不完全是。
private static Rectangle MaintainAspectRatio(Image imgPhoto, Rectangle thumbRect)
{
    int sourceWidth = imgPhoto.Width; int sourceHeight = imgPhoto.Height; int sourceX = 0; int sourceY = 0; int destX = 0; int destY = 0;

    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;

    nPercentW = ((float)thumbRect.Width / (float)sourceWidth);
    nPercentH = ((float)thumbRect.Height / (float)sourceHeight);

    //if we have to pad the height pad both the top and the bottom
    //with the difference between the scaled height and the desired height
    if (nPercentH < nPercentW)
    {
        nPercent = nPercentH;
        destX = (int)((thumbRect.Width - (sourceWidth * nPercent)) / 2);
    }
    else
    {
        nPercent = nPercentW;
        destY = (int)((thumbRect.Height - (sourceHeight * nPercent)) / 2);
    }

    int destWidth = (int)(sourceWidth * nPercent);
    int destHeight = (int)(sourceHeight * nPercent);

    Rectangle retRect = new Rectangle(thumbRect.X, thumbRect.Y, destWidth, destHeight);
    return retRect;
}
pX1 = scaledX1/scaled_width
pY1 = scaledY1/scaled_height

unscaledX1 = ceiling(unscaled_width * pX1)
unscaledY1 = ceiling(unscaled_height * pY1)
NewTop    = ((   OldTop    ) * NewHeight / OldHeight);
NewLeft   = ((   OldLeft   ) * NewWidth  / OldWidth );

NewBottom = ((OldBottom + 1) * NewHeight / OldHeight) - 1;
NewRight  = ((OldRight  + 1) * NewWidth  / OldWidth ) - 1;