private void ShowGallerySelectionImages(TheImage obj)
        {
            if (imglist.LargeImageList != null && imglist.LargeImageList.Images.Count > 0)
            {
                imglist.LargeImageList.Images.Clear();
            }
            SelectedImageKeys.Clear();
            imglist.Clear();//imglist.LargeImageList.Images.Clear();
            imageIO.CreateImageListFromThumbnails(obj, imgs);
            imglist.LargeImageList = imgs;
            CheckForMaxImageWarning();

            foreach (var item in obj.PeerImages)
            {
                //SelectImage(item);
                // image key is the image sleected from imagelist collection, key must present in imagelist above
                //var lvitem = new ListViewItem(item.ImageName, item.ImageKey);
                //SelectedImageChecked(lvitem);
                imglist.Items.Add(item.ImageName, item.ImageKey);
            }

            foreach (ListViewItem item in imglist.Items)
            {
                SelectImage(item);
            }

            imglist.Show();
        }
示例#2
0
        //private Image ResizeHighQualityImage(System.Drawing.Image image, int width, int height)
        //{

        //    Bitmap result;
        //    // the resized result bitmap
        //    result = new Bitmap(width, height);

        //        // get the graphics and draw the passed image to the result bitmap
        //        using (Graphics grphs = Graphics.FromImage(result))
        //        {
        //            grphs.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        //            grphs.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //            grphs.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //            grphs.DrawImage(image, 0, 0, result.Width, result.Height);
        //        }
        //        //Image i = new Bitmap(result);
        //        //// check the quality passed in
        //        //if ((quality < 0) || (quality > 100))
        //        //{
        //        //    string error = string.Format("quality must be 0, 100", quality);
        //        //    throw new ArgumentOutOfRangeException(error);
        //        //}

        //        //EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
        //        //string lookupKey = "image/jpeg";
        //        //var jpegCodec = ImageCodecInfo.GetImageEncoders().Where(i => i.MimeType.Equals(lookupKey)).FirstOrDefault();

        //        ////create a collection of EncoderParameters and set the quality parameter
        //        //var encoderParams = new EncoderParameters(1);
        //        //encoderParams.Param[0] = qualityParam;
        //        ////save the image using the codec and the encoder parameter
        //        //result.Save(pathToSave, jpegCodec, encoderParams);

        //    return result;
        //}


        /// <summary>
        /// Resize the image to the specified width and height.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width to resize to.</param>
        /// <param name="height">The height to resize to.</param>
        /// <returns>The resized image.</returns>
        //private static Bitmap ResizeImage(Image image, int width, int height)
        //{
        //    var destRect = new Rectangle(0, 0, width, height);
        //    var destImage = new Bitmap(width, height);

        //    destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

        //    using (var graphics = Graphics.FromImage(destImage))
        //    {
        //        graphics.CompositingMode = CompositingMode.SourceCopy;
        //        graphics.CompositingQuality = CompositingQuality.HighQuality;
        //        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
        //        graphics.SmoothingMode = SmoothingMode.HighQuality;
        //        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

        //        using (var wrapMode = new ImageAttributes())
        //        {
        //            wrapMode.SetWrapMode(WrapMode.TileFlipXY);
        //            graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
        //        }
        //    }

        //    return destImage;
        //}


        //private Image resizeImage(Image imgToResize, Size size)
        //{
        //    if (imgToResize.Width < 100 | imgToResize.Height < 100)
        //    {
        //        return imgToResize;
        //    }
        //    int sourceWidth = imgToResize.Width;
        //    int sourceHeight = imgToResize.Height;

        //    float nPercent = 0;
        //    float nPercentW = 0;
        //    float nPercentH = 0;

        //    nPercentW = ((float)size.Width / (float)sourceWidth);
        //    nPercentH = ((float)size.Height / (float)sourceHeight);

        //    if (nPercentH < nPercentW)
        //        nPercent = nPercentH;
        //    else
        //        nPercent = nPercentW;

        //    int destWidth = (int)(sourceWidth * nPercent);
        //    int destHeight = (int)(sourceHeight * nPercent);

        //    Bitmap b = new Bitmap(destWidth, destHeight);
        //    Graphics g = Graphics.FromImage((Image)b);
        //    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

        //    g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
        //    g.Dispose();

        //    return (Image)b;
        //}

        //private void CreateImageList(ChitraKiAlbumAurVivaran obj)
        //{
        //    imgs.ImageSize = new Size(200, 200);
        //    imgs.ColorDepth = ColorDepth.Depth32Bit;
        //    List<Image> images = new List<Image>();

        //    foreach (var item in obj.PeerImages)
        //    {
        //        using (Image im = Image.FromFile(item.ImageFullName))
        //        {
        //            //images.Add();
        //            var imtemp = ResizeImage(im, 200, 200);
        //            imgs.Images.Add(item.ImageKey, imtemp);
        //            //im.Dispose();// = null;
        //        }
        //    }
        //}



        private void ShowGallerySelectionImages(ChitraKiAlbumAurVivaran obj)
        {
            imglist.Clear();
            imageIO.CreateImageListFromThumbnails(obj, imgs);
            imglist.LargeImageList = imgs;
            CheckForMaxImageWarning();
            foreach (var item in obj.PeerImages)
            {
                // image key is the image sleected from imagelist collection, key must present in imagelist above
                imglist.Items.Add(item.ImageName, item.ImageKey);
                imglist.Show();
            }

            // Dont show folder icon..
            ////imgs.Images.Add(obj.ImageKey, Image.FromFile(obj.ImageFullName).GetThumbnailImage(200, 200, null, IntPtr.Zero));
            ////imgs.ImageSize = new Size(200, 200);

            ////imglist.Items.Add(obj.ImageName, obj.ImageKey);
            ////imglist.Show();
        }