Пример #1
0
        /// <summary>
        /// Generates a preview image and populates a new
        /// <see cref="PreviewFile"/> object.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="p"></param>
        /// <param name="fmt"></param>
        /// <param name="mime"></param>
        /// <param name="ici"></param>
        /// <param name="eparams"></param>
        /// <returns></returns>
        private PreviewFile lowGenImg(ref Bitmap img,
            Preview p,
            ImageFormat fmt,
            string mime,
            ImageCodecInfo ici,
            EncoderParameters eparams)
        {
            if (p.Name != "square") {
            int[] c = Gfx.GetConstraints(MediaFile.Width, MediaFile.Height,
                                         p.Width, p.Height);

            using (Bitmap n = Gfx.ScaleImage(img, c[0], c[1])) {
            if (!orgIsScaled) {
            img = (Bitmap)n.Clone();
            orgIsScaled = true;
            }

            using (MemoryStream s = new MemoryStream())
            {
            if (ici != null)
                n.Save(s, ici, eparams);
            else
                n.Save(s, fmt);

            PreviewFile pf = new PreviewFile();
            pf.Width = n.Width;
            pf.Height = n.Height;
            pf.Size = s.Length;
            pf.Mimetype = mime;
            pf.Name = p.Name;
            pf.Data = s.ToArray();

            s.Close();
            return pf;
            }
            }
            }
            else {
            int[] c = Gfx.GetConstraintsSq(MediaFile.Width, MediaFile.Height,
                                           p.Width, p.Height);

            using (Bitmap n = Gfx.ScaleImageSq(img, Math.Min(c[0], c[1]))) {
            if (!orgIsScaled) {
            img = (Bitmap)n.Clone();
            orgIsScaled = true;
            }

            using (MemoryStream s = new MemoryStream()) {
            if (ici != null)
              n.Save(s, ici, eparams);
            else
              n.Save(s, fmt);

            PreviewFile pf = new PreviewFile();
            pf.Width = n.Width;
            pf.Height = n.Height;
            pf.Size = s.Length;
            pf.Mimetype = mime;
            pf.Name = p.Name;
            pf.Data = s.ToArray();

            s.Close();
            return pf;
            }
            }
            }
        }
Пример #2
0
 public static PreviewFile FromSql(MySqlDataReader rd)
 {
     var pf = new PreviewFile();
     pf.SetFromSql(rd);
     return pf;
 }