Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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# 如何在xamarin Android中裁剪旋转图像?_C#_Android_Xamarin.android_Image Rotation - Fatal编程技术网

C# 如何在xamarin Android中裁剪旋转图像?

C# 如何在xamarin Android中裁剪旋转图像?,c#,android,xamarin.android,image-rotation,C#,Android,Xamarin.android,Image Rotation,我的要求是在旋转后裁剪图像 样本: 我的真实形象: 轮换后: 在这里,我将图像旋转了45度。现在我只想裁剪高亮显示的(红色矩形)矩形区域。 代码: 请告诉我如何在旋转后找到图像坐标点。您可以裁剪屏幕视图并自定义屏幕框架 例如,CustomShot方法如下: public Bitmap CustomShot(Activity activity, int x, int y, int w, int h) { // get the top view of windows View v

我的要求是在旋转后裁剪图像

样本:

我的真实形象:

轮换后:

在这里,我将图像旋转了45度。现在我只想裁剪高亮显示的(红色矩形)矩形区域。

代码:


请告诉我如何在旋转后找到图像坐标点。

您可以裁剪屏幕视图并自定义屏幕框架

例如,
CustomShot
方法如下:

public Bitmap CustomShot(Activity activity, int x, int y, int w, int h)
{
    // get the top view of windows
    View view = activity.Window.DecorView;
    view.BuildDrawingCache();

    // get the height of status bar
    Rect rect = new Rect();
    view.GetWindowVisibleDisplayFrame(rect);
    int statusBarHeights = rect.Top;
    Display display = activity.WindowManager.DefaultDisplay;

    // get the width and height of screen
    if (w == 0)
    {
        w = display.Width;
    }
       
    int heights = display.Height;

    // allow cache
    view.DrawingCacheEnabled = true;

    // custom the crop frame
    Bitmap bmp = Bitmap.CreateBitmap(view.GetDrawingCache(true), x,
            y, w, h);

    // clear cache
    view.DestroyDrawingCache();

    return bmp;
}
private void Cropbutton_Click(object sender, System.EventArgs e)
{
    if(imageBitmap == null){
        imageBitmap = ViewToBitmap();
        this.imageView.SetImageBitmap(GetCroppedBitmap(imageBitmap, points));
    }else{
        this.imageView.SetImageBitmap(CustomShot( this, 0, 300, 0, 500));
        this.imageView.SetScaleType(ImageView.ScaleType.FitCenter);
        this.imageView.Rotation = 0;
    }
}
然后在
Cropbutton\u单击
方法中使用,如下所示:

public Bitmap CustomShot(Activity activity, int x, int y, int w, int h)
{
    // get the top view of windows
    View view = activity.Window.DecorView;
    view.BuildDrawingCache();

    // get the height of status bar
    Rect rect = new Rect();
    view.GetWindowVisibleDisplayFrame(rect);
    int statusBarHeights = rect.Top;
    Display display = activity.WindowManager.DefaultDisplay;

    // get the width and height of screen
    if (w == 0)
    {
        w = display.Width;
    }
       
    int heights = display.Height;

    // allow cache
    view.DrawingCacheEnabled = true;

    // custom the crop frame
    Bitmap bmp = Bitmap.CreateBitmap(view.GetDrawingCache(true), x,
            y, w, h);

    // clear cache
    view.DestroyDrawingCache();

    return bmp;
}
private void Cropbutton_Click(object sender, System.EventArgs e)
{
    if(imageBitmap == null){
        imageBitmap = ViewToBitmap();
        this.imageView.SetImageBitmap(GetCroppedBitmap(imageBitmap, points));
    }else{
        this.imageView.SetImageBitmap(CustomShot( this, 0, 300, 0, 500));
        this.imageView.SetScaleType(ImageView.ScaleType.FitCenter);
        this.imageView.Rotation = 0;
    }
}
其效果是: