LunarPresentation/Commands/PasteImageFromClipboard.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Drawing;
using System.IO;
using System.Windows;
using WinForm = System.Windows.Forms;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        /// <summary>
        /// 如果当前公式是图片框,则会将剪贴板中的图像数据粘贴进这个图片框;
        /// 如果当前公式不是图片框,则会自动新插入一个图片框,并将剪贴板中的图像数据粘贴进这个新插入的图片框。
        /// </summary>
        public static void PasteImageFromClipboard()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            LunarPresentation.Expressions.Expression curEx
                = Globals.selectedEditor.SelectedExpression;

            PasteImageFromClipboard(curEx);
        }

        public static bool PasteImageFromClipboard(Expressions.Expression ex)
        {
            if (ex == null) return false;

            Expressions.PictureBox pictureBox = null;

            WinForm.IDataObject oDataObj = WinForm.Clipboard.GetDataObject();
            if (oDataObj != null)
            {
                if (oDataObj.GetDataPresent(DataFormats.Bitmap))
                {
                    Image oImgObj = oDataObj.GetData(DataFormats.Bitmap, true) as Image;

                    using (MemoryStream stm = new MemoryStream())
                    {
                        if (oImgObj == null)
                        {
                            MessageBox.Show("未能顺利取出剪贴板中的图像数据!"
                                + "请将图片加工一下或另选一张图片。",
                                    Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
                            return false;
                        }

                        // 准备“撤销”与“重做”所需要的数据。
                        ModifingItem mi = new ModifingItem();

                        if (ex is Expressions.PictureBox)
                        {
                            pictureBox = ex as Expressions.PictureBox;
                        }
                        else
                        {
                            if (ex is Expressions.SubPanel)
                            {
                                MessageBox.Show("请另选一个公式,不能在子面板上粘贴图片。",
后面还有 75 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。