Beispiel #1
0
        public static IProjectItem AddImageDataFromClipboard(IProjectManager projectManager, IProject project)
        {
            InteropBitmap data;
            IProjectItem  projectItem;

            try
            {
                data = (InteropBitmap)Clipboard.GetData(DataFormats.Bitmap);
                goto Label0;
            }
            catch (OutOfMemoryException outOfMemoryException)
            {
                LowMemoryMessage.Show();
                projectItem = null;
            }
            return(projectItem);

Label0:
            if (data == null)
            {
                return(null);
            }
            FormatConvertedBitmap formatConvertedBitmap = new FormatConvertedBitmap(data, PixelFormats.Bgr32, null, 0);
            string str = projectManager.TargetFolderForProject(project);
            string availableFilePath = ProjectPathHelper.GetAvailableFilePath("Image.png", str, null);

            using (FileStream fileStream = new FileStream(availableFilePath, FileMode.Create, FileAccess.Write))
            {
                PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
                pngBitmapEncoder.Frames.Add(BitmapFrame.Create(formatConvertedBitmap));
                pngBitmapEncoder.Save(fileStream);
                fileStream.Close();
            }
            DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo()
            {
                SourcePath = availableFilePath,
                TargetPath = availableFilePath
            };

            return(project.AddItem(documentCreationInfo));
        }
Beispiel #2
0
 public static string GetAvailableFilePath(string fileOrDirectoryName, string targetFolder, IProject project)
 {
     return(ProjectPathHelper.GetAvailableFilePath(fileOrDirectoryName, targetFolder, project, false));
 }