wp7画图

2023-11-20 15:18
文章标签 画图 wp7

本文主要是介绍wp7画图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

<!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <!--TitlePanel 包含应用程序的名称和页标题-->
        <Grid>
            <InkPresenter x:Name="MyPresenter"   
                  HorizontalAlignment="Left"  
                  VerticalAlignment="Top"   
                  MouseLeftButtonDown="MyPresenter_MouseLeftButtonDown"  
                  LostMouseCapture="MyPresenter_LostMouseCapture"  
                  MouseMove="MyPresenter_MouseMove"  
                  Background="Transparent"  
                  Opacity="1" Width="480" Height="750" />
        </Grid>
        <!--ContentPanel - 在此处放置其他内容-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"></Grid>
    </Grid>


    <!--演示 ApplicationBar 用法的示例代码-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="appbar.save.rest.png" Text="保存" Click="ApplicationBarIconButton_Click" />


            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="PenBlue" Click="ApplicationBarMenuItem_Click_1" />
                <shell:ApplicationBarMenuItem Text="PenBrown" Click="ApplicationBarMenuItem_Click_2" />
                <shell:ApplicationBarMenuItem  Text="PenCyan" Click="ApplicationBarMenuItem_Click_3" />
                <shell:ApplicationBarMenuItem Text="PenDarkGray" Click="ApplicationBarMenuItem_Click_4" />
                <shell:ApplicationBarMenuItem Text="PenGray" Click="ApplicationBarMenuItem_Click_5" />
                <shell:ApplicationBarMenuItem  Text="PenGreen" Click="ApplicationBarMenuItem_Click_6" />
                <shell:ApplicationBarMenuItem Text="PenLightGray" Click="ApplicationBarMenuItem_Click_7" />
                <shell:ApplicationBarMenuItem Text="PenMagenta" Click="ApplicationBarMenuItem_Click_8" />
                <shell:ApplicationBarMenuItem  Text="PenOrange" Click="ApplicationBarMenuItem_Click_9" />
                <shell:ApplicationBarMenuItem Text="PenPurple" Click="ApplicationBarMenuItem_Click_10" />
                <shell:ApplicationBarMenuItem Text="PenRed" Click="ApplicationBarMenuItem_Click_11" />
                <shell:ApplicationBarMenuItem  Text="PenTransparent" Click="ApplicationBarMenuItem_Click_12" />
                <shell:ApplicationBarMenuItem Text="PenWhite" Click="ApplicationBarMenuItem_Click_13" />
                <shell:ApplicationBarMenuItem Text="PenYellow" Click="ApplicationBarMenuItem_Click_14" />


            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>

    </phone:PhoneApplicationPage.ApplicationBar>


后台代码:


    public partial class MainPage : PhoneApplicationPage
    {
        Stroke CurrentStroke = null;
        string penColor = "";
        // 构造函数
        public MainPage()
        {
            InitializeComponent();


            // 设置剪辑,以便收集墨迹  
            RectangleGeometry rg = new RectangleGeometry();
            // 为了使范围准确,应使用控件的最终呈现高度。  
            rg.Rect = new Rect(0, 0, MyPresenter.ActualWidth, MyPresenter.ActualHeight);
            MyPresenter.Clip = rg;
        }


        private void MyPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // 当我们点击时获捉鼠标光标  
            MyPresenter.CaptureMouse();
            // 收集当前的光标所在的位置的点  
            StylusPointCollection sc = new StylusPointCollection();
            sc.Add(e.StylusDevice.GetStylusPoints(MyPresenter));
            CurrentStroke = new Stroke(sc);
            // 设置笔触的颜色,大小  
            if (penColor == "Black") { CurrentStroke.DrawingAttributes.Color = Colors.Black; }
            else if (penColor == "Blue") { CurrentStroke.DrawingAttributes.Color = Colors.Blue; }
            else if (penColor == "Brown") { CurrentStroke.DrawingAttributes.Color = Colors.Brown; }
            else if (penColor == "Cyan") { CurrentStroke.DrawingAttributes.Color = Colors.Cyan; }
            else if (penColor == "DarkGray") { CurrentStroke.DrawingAttributes.Color = Colors.DarkGray; }
            else if (penColor == "Gray") { CurrentStroke.DrawingAttributes.Color = Colors.Gray; }
            else if (penColor == "Green") { CurrentStroke.DrawingAttributes.Color = Colors.Green; }
            else if (penColor == "LightGray") { CurrentStroke.DrawingAttributes.Color = Colors.LightGray; }
            else if (penColor == "Magenta") { CurrentStroke.DrawingAttributes.Color = Colors.Magenta; }
            else if (penColor == "Orange") { CurrentStroke.DrawingAttributes.Color = Colors.Orange; }
            else if (penColor == "Purple") { CurrentStroke.DrawingAttributes.Color = Colors.Purple; }
            else if (penColor == "Red") { CurrentStroke.DrawingAttributes.Color = Colors.Red; }
            else if (penColor == "Transparent") { CurrentStroke.DrawingAttributes.Color = Colors.Transparent; }
            else if (penColor == "White") { CurrentStroke.DrawingAttributes.Color = Colors.White; }
            else { CurrentStroke.DrawingAttributes.Color = Colors.Yellow; }
            CurrentStroke.DrawingAttributes.Width = 8;
            CurrentStroke.DrawingAttributes.Height = 8;
            // 把新的笔触添加到集合中  
            MyPresenter.Strokes.Add(CurrentStroke);
        }


        private void MyPresenter_LostMouseCapture(object sender, MouseEventArgs e)
        {
            // 当释放鼠标时,也同时释放笔触变量的引用  
            CurrentStroke = null;
        }


        private void MyPresenter_MouseMove(object sender, MouseEventArgs e)
        {
            if (CurrentStroke != null)
            {
                // 每移动一次鼠标,都收集对应的点。  
                CurrentStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyPresenter));
            }
        }


        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {


            WriteableBitmap bmp = new WriteableBitmap(480, 800);
            bmp.Render(App.Current.RootVisual, null);
            bmp.Invalidate();
            MemoryStream stream = new MemoryStream();
            bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 80);
            stream.Seek(0, SeekOrigin.Begin);
            MediaLibrary library = new MediaLibrary();
            string filename = "Screen" + DateTime.Now.ToString("yyyy-MM-dd_hh:mm:ss") + ".jpg";
            library.SavePicture(filename, stream);


            stream.Close();
            MessageBox.Show("已保存到媒体库!!");


        }


        private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
        {
            penColor = "Blue";
        }


        private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e)
        {
            penColor = "Brown";
        }


        private void ApplicationBarMenuItem_Click_3(object sender, EventArgs e)
        {
            penColor = "Cyan";
        }


        private void ApplicationBarMenuItem_Click_4(object sender, EventArgs e)
        {
            penColor = "DarkGray";


        }


        private void ApplicationBarMenuItem_Click_5(object sender, EventArgs e)
        {
            penColor = "Gray";
        }


        private void ApplicationBarMenuItem_Click_6(object sender, EventArgs e)
        {
            penColor = "Green";
        }


        private void ApplicationBarMenuItem_Click_7(object sender, EventArgs e)
        {
            penColor = "LightGray";
        }


        private void ApplicationBarMenuItem_Click_8(object sender, EventArgs e)
        {
            penColor = "Magenta";


        }


        private void ApplicationBarMenuItem_Click_9(object sender, EventArgs e)
        {
            penColor = "Orange";
        }


        private void ApplicationBarMenuItem_Click_10(object sender, EventArgs e)
        {
            penColor = "Purple";
        }


        private void ApplicationBarMenuItem_Click_11(object sender, EventArgs e)
        {
            penColor = "Red";
        }


        private void ApplicationBarMenuItem_Click_12(object sender, EventArgs e)
        {
            penColor = "Transparent";


        }


        private void ApplicationBarMenuItem_Click_13(object sender, EventArgs e)
        {
            penColor = "White";
        }


        private void ApplicationBarMenuItem_Click_14(object sender, EventArgs e)
        {
            penColor = "Yellow";
        }


    }

这里需要一个类

    public class CommonHelper
    {
        public static void MsgBox(string msg)
        {
            ToastPrompt prompt = new ToastPrompt();
            prompt.Message = msg;
            prompt.Show();
        }
    }

这篇关于wp7画图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/395546

相关文章

Windows11电脑上自带的画图软件修改照片大小(不裁剪尺寸的情况下)

针对一张图片,有时候上传的图片有大小限制,那么在这种情况下如何修改其大小呢,在不裁剪尺寸的情况下 步骤如下: 1.选定一张图片,右击->打开方式->画图,如下: 第二步:打开图片后,我们可以看到图片的大小为82.1kb,点击上面工具栏的“重设大小和倾斜”进行调整,如下: 第三步:修改水平和垂直的数字,此处我修改为分别都修改为50,然后保存,可以看到大小变成63.5kb,如下:

程序员都在使用的画图工具

大家好,我是袁庭新。 程序员都在使用的画图工具,你一定没用过这款画图工具吧!我教程中的架构图都是用它来画的。 比如我编写的RDB工作原理图就是用draw.io绘制的,如下图所示: 再例如Redis集群故障恢复原理图我也是通过draw.io工具绘制的,如下图所示: 是不是觉得draw.io绘制的图形特别简洁、美观。它的官网是: https://www.drawio.com dra

python画图|3D图基础教程

python画3D图和2D流程类似: 【a】定义一个自变量x; 【b】定义两个因变量y和z; 【c】直接输出plot(x,y,z) 今天就一起快乐学习一下画3D图的基础教程。 【1】官网教程 打开官网,可以迅速找到学习教程,参考下述链接: https://matplotlib.org/stable/plot_types/3D/plot3d_simple.html 然后我们解读一下示

python画图|垂线标记系列

进行了一段时间的直方图学习之后,发现python的matplo居然还支持画垂线标记图,赶紧把它记录下来。 直方图绘制教程见下述链接: 【a】直方图绘制基础教程:python画图|直方图绘制教程-CSDN博客 【b】 直方图绘制进阶教程:python画图|直方图绘制教程进阶-CSDN博客 【c】 堆叠直方图绘制教程:python画图|堆叠直方图绘制-CSDN博客 【d】并列直方图绘制教程:

【python 数据可视化】美丽漂亮的画图神器--pyecharts

今天我们介绍下pyechats 的用法和一个简单的例子。 安装: pip install pyecharts 步骤1:导入相关包: # 导入包import pandas as pdfrom pyecharts.charts import *from pyecharts import options as optsfrom pyecharts.globals import *f

plot()画图,横或纵坐标出现乱序

现象: import matplotlib.pyplot as plt plt.plot(x, y, ‘-’) 画折线图,出现了如下,纵坐标数据密集显示,放大之后,出现了乱序。 解决方法: 1.先查看横纵坐标的数据类型。 print(“type:”, type(y)). 我这里打印是字符串类型。 type: <class ‘str’> 2.横纵坐标数据类型需要是int ,float

python画图|并列直方图绘制

前述学习过程中,已经知晓普通直方图绘制和堆叠直方图绘制,参考链接如下: 西猫雷婶-CSDN博客 有时候,我们还会遇到并列直方图绘制的需求,今天就探索一下。 【1】官网教程 按照惯例,我们先来到官网: https://matplotlib.org/stable/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lin

【科研绘图】【3D轨线图】:附Origin详细画图流程

目录 No.1 理解3D轨线图 No.2 画图流程 1 导入数据并绘图 2 设置绘图细节 3 设置坐标轴 4 效果图 No.1 理解3D轨线图 3D轨线图,是指在三维坐标系中,通过连续的点或线段连接而成的图形,用于表示一个或多个物体在三维空间中的运动路径。这些路径可以是直线、曲线或者更复杂的轨迹,它们随时间的变化而变化,从而展示物体的动态行为。 No.2 画图

【CanMV K230】画图,画它个多啦A梦

【CanMV K230】画图,画它个多啦A梦 image对象构造函数使用方法画线段 image.draw_line画矩形 image.draw_rectangle画圆 image.draw_circle绘制椭圆 image.draw_ellipse画箭头 image.draw_arrow画十字交叉 image.draw_cross写字符 image.draw_string写字符,支持中文 i

【收藏】IT人必备,一款免费超好用的画图工具

1.概述        作为一个IT人,日常工作中,常常会需要画各种图,比如架构图、部署架构图、流程图、时序图、泳道图等等,收费的画图软件有很多,比如什么processon、wps之类的,小编就不再过多介绍。       今天主要给大家推荐一款免费的画图软件 draw,draw界面简洁直观、支持多平台windows、macOS、Linux,同时还提供网页在线版,无需安装,真正做到开箱即用。