WPF 实现截屏控件之移动(二)(仿微信)

WPF开发者QQ群

此群已满340500857 ,请加新群458041663

       由于微信群人数太多入群请添加小编微信号

 yanjinhuawechatW_Feng_aiQ 邀请入群

 需备注WPF开发者 

 接着上一篇,兼容屏幕缩放问题。

01

代码如下

一、创建ScreenCut.xaml代码如下。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:controls="clr-namespace:WPFDevelopers.Controls"><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="Basic/ControlBasic.xaml"/><ResourceDictionary Source="ButtonsStyles.xaml"/></ResourceDictionary.MergedDictionaries><Style x:Key="RectangleStyle" TargetType="{x:Type Rectangle}"><Setter Property="Fill" Value="{DynamicResource BlackSolidColorBrush}"/><Setter Property="Opacity" Value=".5"/></Style><Style TargetType="{x:Type controls:ScreenCut}" BasedOn="{StaticResource ControlBasicStyle}"><Setter Property="WindowState" Value="Maximized"/><Setter Property="WindowStyle" Value="None"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type controls:ScreenCut}"><Canvas x:Name="PART_Canvas"Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}}"Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}}"><Rectangle x:Name="PART_RectangleLeft" Style="{DynamicResource RectangleStyle}"/><Rectangle x:Name="PART_RectangleTop" Style="{DynamicResource RectangleStyle}"/><Rectangle x:Name="PART_RectangleRight" Style="{DynamicResource RectangleStyle}"/><Rectangle x:Name="PART_RectangleBottom" Style="{DynamicResource RectangleStyle}"/><Border x:Name="PART_Border" BorderBrush="{DynamicResource PrimaryNormalSolidColorBrush}" BorderThickness="1" Background="Transparent" Cursor="SizeAll"/><WrapPanel x:Name="PART_WrapPanel" Visibility="Hidden" Panel.ZIndex="99"Height="38" Background="{DynamicResource WhiteSolidColorBrush}"VerticalAlignment="Center"><Button x:Name="PART_ButtonSave" Style="{DynamicResource PathButton}"ToolTip="保存" Margin="10,0,0,0"><Button.Content><Path Fill="{DynamicResource InfoPressedSolidColorBrush}" Width="18" Height="18" Stretch="Fill" Data="{StaticResource PathSave}"/></Button.Content></Button><Button x:Name="PART_ButtonCancel" Style="{DynamicResource PathButton}"ToolTip="取消"><Button.Content><Path Fill="{DynamicResource DangerPressedSolidColorBrush}" Width="14" Height="14" Stretch="Fill" Data="{StaticResource PathCancel}"/></Button.Content></Button><Button x:Name="PART_ButtonComplete"  Style="{DynamicResource PathButton}"ToolTip="完成" Margin="0,0,10,0"><Button.Content><Path Fill="{DynamicResource SuccessPressedSolidColorBrush}"  Width="20" Height="15" Stretch="Fill" Data="{StaticResource PathComplete}"/></Button.Content></Button></WrapPanel></Canvas></ControlTemplate></Setter.Value></Setter></Style>
</ResourceDictionary>

二、创建ScreenCut.cs代码如下。

using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPFDevelopers.Helpers;namespace WPFDevelopers.Controls
{[TemplatePart(Name = CanvasTemplateName, Type = typeof(Canvas))][TemplatePart(Name = RectangleLeftTemplateName, Type = typeof(Rectangle))][TemplatePart(Name = RectangleTopTemplateName, Type = typeof(Rectangle))][TemplatePart(Name = RectangleRightTemplateName, Type = typeof(Rectangle))][TemplatePart(Name = RectangleBottomTemplateName, Type = typeof(Rectangle))][TemplatePart(Name = BorderTemplateName, Type = typeof(Border))][TemplatePart(Name = WrapPanelTemplateName, Type = typeof(WrapPanel))][TemplatePart(Name = ButtonSaveTemplateName, Type = typeof(Button))][TemplatePart(Name = ButtonCancelTemplateName, Type = typeof(Button))][TemplatePart(Name = ButtonCompleteTemplateName, Type = typeof(Button))]public class ScreenCut : Window{private const string CanvasTemplateName = "PART_Canvas";private const string RectangleLeftTemplateName = "PART_RectangleLeft";private const string RectangleTopTemplateName = "PART_RectangleTop";private const string RectangleRightTemplateName = "PART_RectangleRight";private const string RectangleBottomTemplateName = "PART_RectangleBottom";private const string BorderTemplateName = "PART_Border";private const string WrapPanelTemplateName = "PART_WrapPanel";private const string ButtonSaveTemplateName = "PART_ButtonSave";private const string ButtonCancelTemplateName = "PART_ButtonCancel";private const string ButtonCompleteTemplateName = "PART_ButtonComplete";private Canvas _canvas;private Rectangle _rectangleLeft, _rectangleTop, _rectangleRight, _rectangleBottom;private Border _border;private WrapPanel _wrapPanel;private Button _buttonSave, _buttonCancel, _buttonComplete;private Rect rect;private Point pointStart, pointEnd;private bool isMouseUp = false;private Win32ApiHelper.DeskTopSize size;static ScreenCut(){DefaultStyleKeyProperty.OverrideMetadata(typeof(ScreenCut), new FrameworkPropertyMetadata(typeof(ScreenCut)));}public override void OnApplyTemplate(){base.OnApplyTemplate();_canvas = GetTemplateChild(CanvasTemplateName) as Canvas;_rectangleLeft = GetTemplateChild(RectangleLeftTemplateName) as Rectangle;_rectangleTop = GetTemplateChild(RectangleTopTemplateName) as Rectangle;_rectangleRight = GetTemplateChild(RectangleRightTemplateName) as Rectangle;_rectangleBottom = GetTemplateChild(RectangleBottomTemplateName) as Rectangle;_border = GetTemplateChild(BorderTemplateName) as Border;_wrapPanel = GetTemplateChild(WrapPanelTemplateName) as WrapPanel;_buttonSave = GetTemplateChild(ButtonSaveTemplateName) as Button;if (_buttonSave != null)_buttonSave.Click += _buttonSave_Click;_buttonCancel = GetTemplateChild(ButtonCancelTemplateName) as Button;if (_buttonCancel != null)_buttonCancel.Click += _buttonCancel_Click;_buttonComplete = GetTemplateChild(ButtonCompleteTemplateName) as Button;if (_buttonComplete != null)_buttonComplete.Click += _buttonComplete_Click;_canvas.Background = new ImageBrush(Capture());_rectangleLeft.Width = _canvas.Width;_rectangleLeft.Height = _canvas.Height;}private void _buttonSave_Click(object sender, RoutedEventArgs e){SaveFileDialog dlg = new SaveFileDialog();dlg.FileName = $"WPFDevelopers{DateTime.Now.ToString("yyyyMMddHHmmss")}.jpg";dlg.DefaultExt = ".jpg";dlg.Filter = "image file|*.jpg";if (dlg.ShowDialog() == true){BitmapEncoder pngEncoder = new PngBitmapEncoder();pngEncoder.Frames.Add(BitmapFrame.Create(CutBitmap()));using (var fs = System.IO.File.OpenWrite(dlg.FileName)){pngEncoder.Save(fs);fs.Dispose();fs.Close();}}Close();}private void _buttonComplete_Click(object sender, RoutedEventArgs e){Clipboard.SetImage(CutBitmap());Close();}CroppedBitmap CutBitmap(){_border.Visibility = Visibility.Collapsed;_rectangleLeft.Visibility = Visibility.Collapsed;_rectangleTop.Visibility = Visibility.Collapsed;_rectangleRight.Visibility = Visibility.Collapsed;_rectangleBottom.Visibility = Visibility.Collapsed;var renderTargetBitmap = new RenderTargetBitmap((int)_canvas.Width,(int)_canvas.Height, 96d, 96d, System.Windows.Media.PixelFormats.Default);renderTargetBitmap.Render(_canvas);return new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height));}private void _buttonCancel_Click(object sender, RoutedEventArgs e){Close();}protected override void OnPreviewKeyDown(KeyEventArgs e){if (e.Key == Key.Escape)Close();}protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e){pointStart = e.GetPosition(_canvas);if (!isMouseUp){_wrapPanel.Visibility = Visibility.Hidden;pointEnd = pointStart;rect = new Rect(pointStart, pointEnd);}}protected override void OnPreviewMouseMove(MouseEventArgs e){if (e.LeftButton == MouseButtonState.Pressed){var current = e.GetPosition(_canvas);if (!isMouseUp){MoveAllRectangle(current);}else{if (current != pointStart){var vector = Point.Subtract(current, pointStart);var left = Canvas.GetLeft(_border) + vector.X;var top = Canvas.GetTop(_border) + vector.Y;if (left <= 0)left = 0;if (top <= 0)top = 0;if (left + _border.Width >= _canvas.ActualWidth)left = _canvas.ActualWidth - _border.ActualWidth;if (top + _border.Height >= _canvas.ActualHeight)top = _canvas.ActualHeight - _border.ActualHeight;pointStart = current;Canvas.SetLeft(_border, left);Canvas.SetTop(_border, top);rect = new Rect(new Point(left, top), new Point(left + _border.Width, top + _border.Height));_rectangleLeft.Width = left <= 0 ? 0 : left >= _canvas.ActualWidth ? _canvas.ActualWidth : left;_rectangleLeft.Height = _canvas.ActualHeight;Canvas.SetLeft(_rectangleTop, _rectangleLeft.Width);_rectangleTop.Height = top <= 0 ? 0 : top >= _canvas.ActualHeight ? _canvas.ActualHeight : top;Canvas.SetLeft(_rectangleRight, left + _border.Width);var wRight = _canvas.ActualWidth - (_border.Width + _rectangleLeft.Width);_rectangleRight.Width = wRight <= 0 ? 0 : wRight;_rectangleRight.Height = _canvas.ActualHeight;Canvas.SetLeft(_rectangleBottom, _rectangleLeft.Width);Canvas.SetTop(_rectangleBottom, top + _border.Height);_rectangleBottom.Width = _border.Width;var hBottom = _canvas.ActualHeight - (top + _border.Height);_rectangleBottom.Height = hBottom <= 0 ? 0 : hBottom;}}}}protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e){_wrapPanel.Visibility = Visibility.Visible;Canvas.SetLeft(_wrapPanel, rect.X + rect.Width - _wrapPanel.ActualWidth);var y = Canvas.GetTop(_border) + _border.ActualHeight + _wrapPanel.ActualHeight;if (y > _canvas.ActualHeight)y = Canvas.GetTop(_border) - _wrapPanel.ActualHeight - 4;elsey = Canvas.GetTop(_border) + _border.ActualHeight + 4;Canvas.SetTop(_wrapPanel, y);isMouseUp = true;}void MoveAllRectangle(Point current){pointEnd = current;rect = new Rect(pointStart, pointEnd);_rectangleLeft.Width = rect.X;_rectangleLeft.Height = _canvas.Height;Canvas.SetLeft(_rectangleTop, _rectangleLeft.Width);_rectangleTop.Width = rect.Width;double h = 0.0;if (current.Y < pointStart.Y)h = current.Y;elseh = current.Y - rect.Height;_rectangleTop.Height = h;Canvas.SetLeft(_rectangleRight, _rectangleLeft.Width + rect.Width);_rectangleRight.Width = _canvas.Width - (rect.Width + _rectangleLeft.Width);_rectangleRight.Height = _canvas.Height;Canvas.SetLeft(_rectangleBottom, _rectangleLeft.Width);Canvas.SetTop(_rectangleBottom, rect.Height + _rectangleTop.Height);_rectangleBottom.Width = rect.Width;_rectangleBottom.Height = _canvas.Height - (rect.Height + _rectangleTop.Height);_border.Height = rect.Height;_border.Width = rect.Width;Canvas.SetLeft(_border, rect.X);Canvas.SetTop(_border, rect.Y);}BitmapSource Capture(){IntPtr hBitmap;IntPtr hDC = Win32ApiHelper.GetDC(Win32ApiHelper.GetDesktopWindow());IntPtr hMemDC = Win32ApiHelper.CreateCompatibleDC(hDC);size.cx = Win32ApiHelper.GetSystemMetrics(0);size.cy = Win32ApiHelper.GetSystemMetrics(1);hBitmap = Win32ApiHelper.CreateCompatibleBitmap(hDC, size.cx, size.cy);if (hBitmap != IntPtr.Zero){IntPtr hOld = (IntPtr)Win32ApiHelper.SelectObject(hMemDC, hBitmap);Win32ApiHelper.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, Win32ApiHelper.TernaryRasterOperations.SRCCOPY);Win32ApiHelper.SelectObject(hMemDC, hOld);Win32ApiHelper.DeleteDC(hMemDC);Win32ApiHelper.ReleaseDC(Win32ApiHelper.GetDesktopWindow(), hDC);var bsource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());Win32ApiHelper.DeleteObject(hBitmap);GC.Collect();return bsource;}return null;}}
}

三、新建WINAPI DLL Imports.cs代码如下。

#region WINAPI DLL Imports[DllImport("gdi32.dll", ExactSpelling = true, PreserveSig = true, SetLastError = true)]public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);[DllImport("gdi32.dll")]public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);[DllImport("gdi32.dll", SetLastError = true)]public static extern IntPtr CreateCompatibleDC(IntPtr hdc);[DllImport("gdi32.dll")]public static extern bool DeleteObject(IntPtr hObject);[DllImport("gdi32.dll")]public static extern IntPtr CreateBitmap(int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits);[DllImport("user32.dll")]public static extern IntPtr GetDC(IntPtr hWnd);[DllImport("user32.dll")]public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);[DllImport("gdi32.dll", EntryPoint = "DeleteDC")]public static extern IntPtr DeleteDC(IntPtr hDc);public const int SM_CXSCREEN = 0;public const int SM_CYSCREEN = 1;[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]public static extern IntPtr GetDesktopWindow();[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]public static extern int GetSystemMetrics(int abc);[DllImport("user32.dll", EntryPoint = "GetWindowDC")]public static extern IntPtr GetWindowDC(Int32 ptr);public struct DeskTopSize{public int cx;public int cy;}public enum TernaryRasterOperations : uint{/// <summary>dest = source</summary>SRCCOPY = 0x00CC0020,/// <summary>dest = source OR dest</summary>SRCPAINT = 0x00EE0086,/// <summary>dest = source AND dest</summary>SRCAND = 0x008800C6,/// <summary>dest = source XOR dest</summary>SRCINVERT = 0x00660046,/// <summary>dest = source AND (NOT dest)</summary>SRCERASE = 0x00440328,/// <summary>dest = (NOT source)</summary>NOTSRCCOPY = 0x00330008,/// <summary>dest = (NOT src) AND (NOT dest)</summary>NOTSRCERASE = 0x001100A6,/// <summary>dest = (source AND pattern)</summary>MERGECOPY = 0x00C000CA,/// <summary>dest = (NOT source) OR dest</summary>MERGEPAINT = 0x00BB0226,/// <summary>dest = pattern</summary>PATCOPY = 0x00F00021,/// <summary>dest = DPSnoo</summary>PATPAINT = 0x00FB0A09,/// <summary>dest = pattern XOR dest</summary>PATINVERT = 0x005A0049,/// <summary>dest = (NOT dest)</summary>DSTINVERT = 0x00550009,/// <summary>dest = BLACK</summary>BLACKNESS = 0x00000042,/// <summary>dest = WHITE</summary>WHITENESS = 0x00FF0062}[DllImport("gdi32.dll")]public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);#endregion}

四、新建ScreenCutExample.xaml.cs代码如下。

var screenCut = new ScreenCut();screenCut.ShowDialog();//screenCut.Show();

02


效果预览

鸣谢素材提供者 - 吴锋

源码地址如下

Github:https://github.com/WPFDevelopersOrg

Gitee:https://gitee.com/WPFDevelopersOrg

WPF开发者QQ群: 340500857 | 458041663

Github:https://github.com/WPFDevelopersOrg

出处:https://www.cnblogs.com/yanjinhua

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请著名作者 出处 https://github.com/WPFDevelopersOrg

4cdd79e13025aa9bc39659f9a61da1e5.png

扫一扫关注我们,

17b05be38a38009a6c8757a26e7e3614.gif

更多知识早知道!

90f3d4ee44e229706ab725b89fdc2557.gif

点击阅读原文可跳转至源代码

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/289933.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

构造不可变类及其优点

不可变类的优点 易于构造&#xff0c;测试和使用天然线程安全&#xff0c;没有同步问题不需要实现clone方法引用不可变类的实例时&#xff0c;不需要考虑实例的值发生变化的情况如何构造不可变类 不声明“setter”方法。所有属性设为private final。class声明为final&#xff0…

深入剖析阿里云推荐引擎——新架构,新体验

摘要&#xff1a;本文的整理自2017云栖大会-上海峰会上阿里云算法专家郑重&#xff08;卢梭&#xff09;的分享讲义&#xff0c;从2016年2月V2.0公开使用到现在&#xff0c;阿里云推荐引擎有了更大的进步。有着获取排序的在线计算&#xff0c;修正匹配的近线计算及匹配排序的离…

分治算法之快速排序

1、快速排序 通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序 2、思路 ( 1 )分解:先从数列中取出一个元素作为基准元素。以基准元素为标准,将问题分解为两个子序列,使小于…

java程序结构_java程序结构

java是一门面向对象的语言&#xff0c;在编程过程中当然离不开对象的声明&#xff0c;而对象又是通过类定义的&#xff0c;所以java中最重要的就是各式各样的类&#xff0c;在java中&#xff0c;类也是一个程序的基本单位0x01&#xff1a;默认生成类在eclipse中创建好一个java类…

C#金额小写转大写

public string ConvertMoney(decimal Money){//金额转换程序string MoneyNum = "";//记录小写金额字符串[输入参数]string MoneyStr = "";//记录大写金额字符串[输出参数]string BNumStr = "零壹贰叁肆伍陆柒捌玖";//模string UnitStr = "万…

SQL Server 2008空间数据应用系列三:SQL Server 2008空间数据类型

SQL Server 2008空间数据应用系列三&#xff1a;SQL Server 2008空间数据类型 原文:SQL Server 2008空间数据应用系列三&#xff1a;SQL Server 2008空间数据类型友情提示&#xff0c;您阅读本篇博文的先决条件如下&#xff1a; 1、本文示例基于Microsoft SQL Server 2008 R2调…

shell脚本中怎样同时执行多个.sql文件,并把结果写入文件中(转)

转载&#xff1a;http://joewalker.iteye.com/blog/408879命令行下具体用法如下&#xff1a; mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;导出整个数据库结构和数据mysqldump -h localhost -uroot -p123456 database > dump.sql导出单个数据表结构和数据mysql…

.NET 很好,你可能对它有一些误解

> 作者&#xff1a;Charles Chen在 20 年前的 2002 年, 微软公布了下一代的软件、服务的愿景和路线&#xff0c;2 月 13 日&#xff0c;Visual Studio .NET 推出&#xff0c;.NET 开发平台的第一个版本正式向世界发布。到现在为止&#xff0c;.NET 都已经 20 岁了, 它已经成…

ajax返回数据类型为JSON数据的处理

ajax返回数据类型为JSON数据的处理 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns"http://www.w3.org/1999/xhtml"> <head> <…

SQL语言实现金额小写转大写完整案例代码

1. 数字大小写对照表 一到十数字大小写: 1——壹,2——贰,3——叁,4——肆,5——伍,6——陆,7——柒,8——捌,9——玖,10——拾 2. 大小写转换案例 将12.345元转换为大写 select dbo.L2U(12.345,1) select dbo.L2U(123456789.345,1) 结果: 3. SQL转化代码 CREA…

Android studio之编译出现 Error:null value in entry: outputDirectory=null

1、问题 昨天编译好好的&#xff0c;今天编译无缘无故报下面这个错 Error:null value in entry: outputDirectorynull 2、解决办法 cd 到项目的根目录去&#xff0c;然后删除.gradle/文件夹就可以了 rm -rf .gradle/

c# 操作excle

添加引用 Microsoft.Office.Interop.Excel; 添加命名空间 using Excel Microsoft.Office.Interop.Excel; //创建接口变量------------------------------------------ _Workbook _xlWorkBook null; Worksheet _xlWorkSheet null; Excel.Application _xlApp null;//创建exc…

mysql 权重 取值_mysql如何按权重查询数据啊?

楼上的回答全都会错意了&#xff0c;题主意思是根据权重设定随机几率&#xff0c;例如 A 的权重为10&#xff0c;B 的权重为 5&#xff0c;这个时候随机出现 A 的几率要比出现 B 的几率高。你可以试试这个备选方案。就是先取出权重列表再去根据权重随机出来的那个权重值&#x…

使用 JsonSchema 验证 API 的返回格式

使用 JsonSchema 验证 API 的返回格式Intro最近我们的 API 提供给了别的团队的小伙伴用&#xff0c;按照他们的需求做了接口的改动&#xff0c;API 返回的数据结构有一些变化&#xff0c;我们提供的接口有缓存&#xff0c;数据库更新之后不会马上刷新&#xff0c;于是就想验证一…

盘点PHP编程常见失误

为什么80%的码农都做不了架构师&#xff1f;>>> 变量声明 如果在一条语句中声明一个变量&#xff0c;如下所示&#xff1a;$varvalue;编译器首先会求出语句右半部分的值&#xff0c;恰恰正是语句的这一部分常常会引发错误。如果使用的语法不正确&#xff0c;就会出…

Scala具体解释---------Scala是什么?可伸展的语言!

Scala是什么 Scala语言的名称来自于“可伸展的语言”。之所以这样命名&#xff0c;是由于他被设计成随着使用者的需求而成长。你能够把Scala应用在非常大范围的编程任务上。从写个小脚本到建立个大系统。51CTO编辑推荐&#xff1a;Scala编程语言专题 Scala是非常easy进入的语言…

地理学:从未磨灭的价值

地理学&#xff1a;从未磨灭的价值 文|梁鹏 庄子说&#xff1a;“天地有大美而不言&#xff0c;四时有明法而不议&#xff0c;万物有成理而不说”&#xff0c;天地不言&#xff0c;四时不议&#xff0c;万物不说&#xff0c;于是地理学家就是替天地说话的那帮人。推开自然之门&…

Android之导入项目提示Android requires compiler compliance level 5.0 or 6.0. Found ‘1.8‘ instead解决办法

1、问题 导入项目eclipse提示如下&#xff1a; Android requires compiler compliance level 5.0 or 6.0. Found 1.8 instead 2、解决办法 项目右键->Android tools->Fix Project

Educational Codeforces Round 1

被C坑的不行不行的。。。其他题目都还可以。 A - Tricky Sum 求1&#xff0c;2&#xff0c;3,...,n的加和&#xff0c;其中2^x&#xff08;x>0&#xff09;为负。 因为2^x的个数很少&#xff0c;所以以每个2^x为分界点进行判断. 初始化x0; 如果n>2^x,求出2^(x-1)到2^(x)之…

自定义View的三个构造函数

自定义View有三个构造方法&#xff0c;它们的作用是不同的。 public MyView(Context context) {super(context); }public MyView(Context context, AttributeSet attrs) {super(context, attrs);}public MyView(Context context, AttributeSet attrs, int defStyleAttr) {su…