Пример #1
0
 public object ConvertBack(
     object value,
     Type targetType,
     object parameter,
     CultureInfo culture)
 {
     return(imagePersistenceService.ConvertBitmapSourceToByteArray((BitmapSource)value));
 }
Пример #2
0
        public IDataSource GetDataSource()
        {
            var activeWindowHandle = windowNativeApi.GetForegroundWindow();

            var windowTitle = windowNativeApi.GetWindowTitle(activeWindowHandle);
            var windowIcon  = GetWindowIcon(activeWindowHandle);

            var iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon);

            return(new DataSource(iconBytes, windowTitle));
        }
Пример #3
0
        public async Task <IDataSource> GetDataSourceAsync()
        {
            var activeWindowHandle = activeWindowService.ActiveWindowHandle;
            var activeWindowTitle  = activeWindowService.GetWindowTitleFromWindowHandle(activeWindowHandle);

            var process     = activeWindowService.GetProcessFromWindowHandle(activeWindowHandle);
            var processName = process.ProcessName + ".exe";

            var iconBytesBig = dataSourceIconCacheLarge.Get(activeWindowHandle);

            if (iconBytesBig == null)
            {
                var windowIconBig = await GetWindowIconAsync(process, activeWindowHandle);

                iconBytesBig = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconBig);

                dataSourceIconCacheLarge.Set(activeWindowHandle, iconBytesBig);
            }

            var iconBytesSmall = dataSourceIconCacheSmall.Get(activeWindowHandle);

            if (iconBytesSmall == null)
            {
                var windowIconSmall = await GetWindowIconAsync(process, activeWindowHandle, false);

                iconBytesSmall = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconSmall);

                dataSourceIconCacheSmall.Set(activeWindowHandle, iconBytesSmall);
            }

            var dataSource = new DataSource(
                iconBytesBig,
                iconBytesSmall,
                activeWindowTitle,
                processName);

            return(dataSource);
        }
Пример #4
0
        public IDataSource GetDataSource()
        {
            lock (this)
            {
                var activeWindowHandle = activeWindowService.ActiveWindowHandle;

                var processName = activeWindowService.
                                  GetProcessFromWindowHandle(activeWindowHandle)
                                  .ProcessName + ".exe";

                var iconBytesBig = dataSourceIconCacheLarge.Get(activeWindowHandle);
                if (iconBytesBig == null)
                {
                    var windowIconBig = GetWindowIcon(activeWindowHandle);
                    iconBytesBig = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconBig);

                    dataSourceIconCacheLarge.Set(activeWindowHandle, iconBytesBig);
                }

                var iconBytesSmall = dataSourceIconCacheSmall.Get(activeWindowHandle);
                if (iconBytesSmall == null)
                {
                    var windowIconSmall = GetWindowIcon(activeWindowHandle, false);
                    iconBytesSmall = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIconSmall);

                    dataSourceIconCacheSmall.Set(activeWindowHandle, iconBytesSmall);
                }

                var dataSource = new DataSource(
                    iconBytesBig,
                    iconBytesSmall,
                    activeWindowService.GetWindowTitleFromWindowHandle(activeWindowHandle),
                    processName);
                return(dataSource);
            }
        }
Пример #5
0
        public IClipboardData BuildData(IClipboardFormat format, byte[] rawData)
        {
            if (!CanBuildData(format))
            {
                throw new InvalidOperationException("The given format is not supported.");
            }

            var bitmapSource = DIBV5ToBitmapSource(rawData);

            return(new ClipboardImageData()
            {
                RawData = rawData,
                RawFormat = format,
                Image = imagePersistenceService.ConvertBitmapSourceToByteArray(bitmapSource)
            });
        }
Пример #6
0
        public byte[] UnwrapStructure(uint format)
        {
            //HACK: we close the clipboard here to avoid it being already open. should definitely be fixed for final release.
            try
            {
                clipboardNativeApi.CloseClipboard();

                var image = Clipboard.GetImage();
                return(imagePersistenceService
                       .ConvertBitmapSourceToByteArray(image));
            }
            finally
            {
                clipboardNativeApi
                .OpenClipboard(mainWindowHandleContainer.Handle);
            }
        }
Пример #7
0
        byte[] GenerateByteArrayFromBitmapHandle(IntPtr bitmapHandle)
        {
            var bitmap = new BITMAP();

            AllocateBitmapSpace(bitmapHandle, ref bitmap);

            try
            {
                FillBitmapBitsIntoHandle(bitmap);

                var bitmapSource = CreateBitmapSourceFromHandle(bitmapHandle, bitmap);
                return(imagePersistenceService.ConvertBitmapSourceToByteArray(bitmapSource));
            }
            finally
            {
                DeleteObject(bitmapHandle);
            }
        }
Пример #8
0
        public IDataSource GetDataSource()
        {
            var activeWindowHandle = windowNativeApi.GetForegroundWindow();
            var windowTitle        = windowNativeApi.GetWindowTitle(activeWindowHandle);

            lock (this)
            {
                byte[] iconBytes;
                if (dataSourceIconCache.ContainsKey(activeWindowHandle))
                {
                    iconBytes = dataSourceIconCache[activeWindowHandle];
                }
                else
                {
                    var windowIcon = GetWindowIcon(activeWindowHandle);
                    iconBytes = imagePersistenceService.ConvertBitmapSourceToByteArray(windowIcon);
                    dataSourceIconCache.Add(activeWindowHandle, iconBytes);
                }

                var dataSource = new DataSource(iconBytes, windowTitle);
                return(dataSource);
            }
        }
 public byte[] GenerateDesignerImageBytesFromFileBytes(byte[] fileBytes)
 {
     var bitmapSource = imageFileInterpreter.Interpret(fileBytes);
     return imagePersistenceService.ConvertBitmapSourceToByteArray(bitmapSource);
 }
Пример #10
0
        byte[] HandleBitmapVersionOne(byte[] bitmapVersionOneBytes, BITMAPINFOHEADER bitmapVersionOneHeader)
        {
            var bitmap = CreateBitmapVersionOne(bitmapVersionOneBytes, bitmapVersionOneHeader);

            return(imagePersistenceService.ConvertBitmapSourceToByteArray(bitmap));
        }