Example #1
0
        /// <summary>
        /// Draws a bitmap from a group of files.
        /// </summary>
        /// <param name="source">The group of files.</param>
        /// <param name="bitDepth">The bits per pixel of the resulting bitmap.</param>
        /// <param name="palette">The palette to use for the resulting bitmap. Pass null if the bit depth is 24 or 32 bits per pixel.</param>
        /// <param name="worker">A BackgroundWorker which receives progress reports and may cancel this method.</param>
        /// <returns>A bitmap containing pixels made from all the bytes of all the files in the group.</returns>
        public static Bitmap Draw(FileSource source, BitDepth bitDepth, int[] palette, BackgroundWorker worker)
        {
            if (source == null || source.FilePaths.Count == 0) throw new ArgumentException("The provided file source was null or had no files.", nameof(source));
            if (bitDepth < 0 || (int)bitDepth > 7) throw new ArgumentOutOfRangeException(nameof(bitDepth), $"The provided bit depth was not a valid value. Expected a value between 0 and 7, got {bitDepth}.");
            if (worker == null) throw new ArgumentNullException(nameof(worker), "The provided BackgroundWorker was null.");

            byte[] sourceBytes = source.GetFiles();

            return Draw(sourceBytes, bitDepth, palette, worker);
        }
Example #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (filePaths != null && filePaths.Length != 0)
            {
                FileSource source = new FileSource(filePaths);
                int[] palette = null;
                if (bitDepth != BitDepth.TwentyFourBpp && bitDepth != BitDepth.ThirtyTwoBpp)
                {
                    palette = DefaultPalettes.GetPalette(bitDepth, colorMode);
                }

                image = Drawer.Draw(source, bitDepth, palette, Worker);
            }
        }