当前位置: 首页>>代码示例>>C#>>正文


C# Media.Picture类代码示例

本文整理汇总了C#中Nop.Core.Domain.Media.Picture的典型用法代码示例。如果您正苦于以下问题:C# Picture类的具体用法?C# Picture怎么用?C# Picture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Picture类属于Nop.Core.Domain.Media命名空间,在下文中一共展示了Picture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMemoryStream

 static MemoryStream GetMemoryStream(Picture picture, int targetSize)
 {
     var localUrl = EngineContext.Current.Resolve<IPictureService>().GetPictureLocalPath(picture, targetSize);
     var fileStream = new FileStream(localUrl, FileMode.Open, FileAccess.Read, FileShare.Read);
     var memoryStream = StreamToMemory(fileStream);
     fileStream.Close();
     return memoryStream;
 }
开发者ID:btolbert,项目名称:test-commerce,代码行数:8,代码来源:ImageResult.cs

示例2: DeletePictureThumbs

 /// <summary>
 /// Delete picture thumbs
 /// </summary>
 /// <param name="picture">Picture</param>
 protected override void DeletePictureThumbs(Picture picture)
 {
     string filter = string.Format("{0}", picture.Id.ToString("0000000"));
     var files = container_thumb.ListBlobs(prefix: filter, useFlatBlobListing: false);
     foreach (var ff in files)
     {
         CloudBlockBlob blockBlob = (CloudBlockBlob)ff;
         blockBlob.Delete();
     }
 }
开发者ID:powareverb,项目名称:grandnode,代码行数:14,代码来源:AzurePictureService.cs

示例3: Can_save_and_load_picture

        public void Can_save_and_load_picture()
        {
            var picture = new Picture
            {
                PictureBinary = new byte[] { 1, 2, 3 },
                MimeType = "image/pjpeg",
                SeoFilename = "seo filename 1",
                IsNew = true
            };

            var fromDb = SaveAndLoadEntity(picture);
            fromDb.ShouldNotBeNull();
            fromDb.PictureBinary.ShouldEqual(new byte[] { 1, 2, 3 });
            fromDb.MimeType.ShouldEqual("image/pjpeg");
            fromDb.SeoFilename.ShouldEqual("seo filename 1");
            fromDb.IsNew.ShouldEqual(true);
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:17,代码来源:PicturePersistenceTests.cs

示例4: Can_save_and_load_picture

        public void Can_save_and_load_picture()
        {
            var picture = new Picture
            {
                PictureBinary = new byte[] { 1, 2, 3 },
                MimeType = MimeTypes.ImagePJpeg,
                SeoFilename = "seo filename 1",
                AltAttribute = "AltAttribute 1",
                TitleAttribute = "TitleAttribute 1",
                IsNew = true
            };

            var fromDb = SaveAndLoadEntity(picture);
            fromDb.ShouldNotBeNull();
            fromDb.PictureBinary.ShouldEqual(new byte[] { 1, 2, 3 });
            fromDb.MimeType.ShouldEqual(MimeTypes.ImagePJpeg);
            fromDb.SeoFilename.ShouldEqual("seo filename 1");
            fromDb.AltAttribute.ShouldEqual("AltAttribute 1");
            fromDb.TitleAttribute.ShouldEqual("TitleAttribute 1");
            fromDb.IsNew.ShouldEqual(true);
        }
开发者ID:RobinHoody,项目名称:nopCommerce,代码行数:21,代码来源:PicturePersistenceTests.cs

示例5: DeletePicture

        /// <summary>
        /// Deletes a picture
        /// </summary>
        /// <param name="picture">Picture</param>
        public virtual void DeletePicture(Picture picture)
        {
            if (picture == null)
                throw new ArgumentNullException("picture");

            //delete thumbs
            DeletePictureThumbs(picture);

            //delete from file system
            if (!this.StoreInDb)
                DeletePictureOnFileSystem(picture);

            //delete from database
            _pictureRepository.Delete(picture);
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:19,代码来源:PictureService.cs

示例6: DeletePictureThumbs

 /// <summary>
 /// Delete picture thumbs
 /// </summary>
 /// <param name="picture">Picture</param>
 protected virtual void DeletePictureThumbs(Picture picture)
 {
     string filter = string.Format("{0}*.*", picture.Id.ToString("0000000"));
     string[] currentFiles = System.IO.Directory.GetFiles(this.LocalThumbImagePath, filter);
     foreach (string currentFileName in currentFiles)
         File.Delete(Path.Combine(this.LocalThumbImagePath, currentFileName));
 }
开发者ID:pquic,项目名称:qCommerce,代码行数:11,代码来源:PictureService.cs

示例7: PictureResult

 public PictureResult(Picture picture, int targetSize)
     : base(GetMemoryStream(picture, targetSize), picture.MimeType)
 {
 }
开发者ID:btolbert,项目名称:test-commerce,代码行数:4,代码来源:ImageResult.cs

示例8: LoadPictureBinary

        /// <summary>
        /// Gets the loaded picture binary depending on picture storage settings
        /// </summary>
        /// <param name="picture">Picture</param>
        /// <param name="fromDb">Load from database; otherwise, from file system</param>
        /// <returns>Picture binary</returns>
        public virtual byte[] LoadPictureBinary(Picture picture, bool fromDb)
        {
            if (picture == null)
                throw new ArgumentNullException("picture");

            byte[] result = null;
            if (fromDb)
                result = picture.PictureBinary;
            else
                result = LoadPictureFromFile(picture.Id, picture.MimeType);
            return result;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:18,代码来源:PictureService.cs

示例9: DeletePictureOnFileSystem

        /// <summary>
        /// Delete a picture on file system
        /// </summary>
        /// <param name="picture">Picture</param>
        protected virtual void DeletePictureOnFileSystem(Picture picture)
        {
            if (picture == null)
                throw new ArgumentNullException("picture");

            string lastPart = GetFileExtensionFromMimeType(picture.MimeType);
            string localFilename = string.Format("{0}_0.{1}", picture.Id.ToString("0000000"), lastPart);
            string localFilepath = Path.Combine(LocalImagePath, localFilename);
            if (File.Exists(localFilepath))
            {
                File.Delete(localFilepath);
            }
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:17,代码来源:PictureService.cs

示例10: InsertPicture

        /// <summary>
        /// Inserts a picture
        /// </summary>
        /// <param name="pictureBinary">The picture binary</param>
        /// <param name="mimeType">The picture MIME type</param>
        /// <param name="seoFilename">The SEO filename</param>
        /// <param name="isNew">A value indicating whether the picture is new</param>
        /// <returns>Picture</returns>
        public virtual Picture InsertPicture(byte[] pictureBinary, string mimeType, string seoFilename, bool isNew)
        {
            mimeType = CommonHelper.EnsureNotNull(mimeType);
            mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);

            seoFilename = CommonHelper.EnsureMaximumLength(seoFilename, 100);

            pictureBinary = ValidatePicture(pictureBinary, mimeType);

            var picture = new Picture();
            picture.PictureBinary = (this.StoreInDb ? pictureBinary : new byte[0]);
            picture.MimeType = mimeType;
            picture.SeoFilename = seoFilename;
            picture.IsNew = isNew;

            _pictureRepository.Insert(picture);

            if(!this.StoreInDb)
                SavePictureInFile(picture.Id, pictureBinary, mimeType);
            return picture;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:29,代码来源:PictureService.cs

示例11: GetPictureLocalPath

 /// <summary>
 /// Get a picture local path
 /// </summary>
 /// <param name="picture">Picture instance</param>
 /// <param name="targetSize">The target picture size (longest side)</param>
 /// <param name="showDefaultPicture">A value indicating whether the default picture is shown</param>
 /// <returns></returns>
 public virtual string GetPictureLocalPath(Picture picture, int targetSize = 0, bool showDefaultPicture = true)
 {
     string url = GetPictureUrl(picture, targetSize, showDefaultPicture);
     if(String.IsNullOrEmpty(url))
         return String.Empty;
     else
         return Path.Combine(this.LocalThumbImagePath, Path.GetFileName(url));
 }
开发者ID:pquic,项目名称:qCommerce,代码行数:15,代码来源:PictureService.cs

示例12: GetPictureUrl

        /// <summary>
        /// Get a picture URL
        /// </summary>
        /// <param name="picture">Picture instance</param>
        /// <param name="targetSize">The target picture size (longest side)</param>
        /// <param name="showDefaultPicture">A value indicating whether the default picture is shown</param>
        /// <returns></returns>
        public virtual string GetPictureUrl(Picture picture, int targetSize = 0, bool showDefaultPicture = true)
        {
            string url = string.Empty;
            if (picture == null || LoadPictureBinary(picture).Length == 0)
            {
                if(showDefaultPicture)
                {
                    url = GetDefaultPictureUrl(targetSize);
                }
                return url;
            }

            string lastPart = GetFileExtensionFromMimeType(picture.MimeType);
            string localFilename;
            if (picture.IsNew)
            {
                DeletePictureThumbs(picture);

                picture = UpdatePicture(picture.Id, LoadPictureBinary(picture), picture.MimeType, picture.SeoFilename, false);
            }
            lock (s_lock)
            {
                string seoFileName = picture.SeoFilename; // = GetPictureSeName(picture.SeoFilename); //just for sure
                if (targetSize == 0)
                {
                    localFilename = !String.IsNullOrEmpty(seoFileName) ?
                        string.Format("{0}_{1}.{2}", picture.Id.ToString("0000000"), seoFileName, lastPart) :
                        string.Format("{0}.{1}", picture.Id.ToString("0000000"), lastPart);

                    if (!File.Exists(Path.Combine(this.LocalThumbImagePath, localFilename)))
                    {
                        if (!System.IO.Directory.Exists(this.LocalThumbImagePath))
                        {
                            System.IO.Directory.CreateDirectory(this.LocalThumbImagePath);
                        }
                        File.WriteAllBytes(Path.Combine(this.LocalThumbImagePath, localFilename), LoadPictureBinary(picture));
                    }
                }
                else
                {
                    localFilename = !String.IsNullOrEmpty(seoFileName) ?
                        string.Format("{0}_{1}_{2}.{3}", picture.Id.ToString("0000000"), seoFileName, targetSize, lastPart) :
                        string.Format("{0}_{1}.{2}", picture.Id.ToString("0000000"), targetSize, lastPart);
                    if (!File.Exists(Path.Combine(this.LocalThumbImagePath, localFilename)))
                    {
                        if (!System.IO.Directory.Exists(this.LocalThumbImagePath))
                        {
                            System.IO.Directory.CreateDirectory(this.LocalThumbImagePath);
                        }
                        using (var stream = new MemoryStream(LoadPictureBinary(picture)))
                        {
                            var b = new Bitmap(stream);

                            var newSize = CalculateDimensions(b.Size, targetSize);

                            if (newSize.Width < 1)
                                newSize.Width = 1;
                            if (newSize.Height < 1)
                                newSize.Height = 1;

                            var newBitMap = new Bitmap(newSize.Width, newSize.Height);
                            var g = Graphics.FromImage(newBitMap);
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                            g.DrawImage(b, 0, 0, newSize.Width, newSize.Height);
                            var ep = new EncoderParameters();
                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, this.ImageQuality);
                            ImageCodecInfo ici = GetImageCodecInfoFromExtension(lastPart);
                            if (ici == null)
                                ici = GetImageCodecInfoFromMimeType("image/jpeg");
                            newBitMap.Save(Path.Combine(this.LocalThumbImagePath, localFilename), ici, ep);
                            newBitMap.Dispose();
                            b.Dispose();
                        }
                    }
                }
            }
            url = _webHelper.GetStoreLocation() + "content/images/thumbs/" + localFilename;
            return url;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:89,代码来源:PictureService.cs

示例13: LoadPictureBinary

        /// <summary>
        /// Gets the loaded picture binary depending on picture storage settings
        /// </summary>
        /// <param name="picture">Picture</param>
        /// <param name="fromDb">Load from database; otherwise, from file system</param>
        /// <returns>Picture binary</returns>
        protected virtual byte[] LoadPictureBinary(Picture picture, bool fromDb)
        {
            if (picture == null)
                throw new ArgumentNullException("picture");

            var result = fromDb
                ? picture.PictureBinary
                : LoadPictureFromFile(picture.Id, picture.MimeType);
            return result;
        }
开发者ID:chamithdev,项目名称:AntiquesWeb,代码行数:16,代码来源:PictureService.cs

示例14: DeletePictureOnFileSystem

        /// <summary>
        /// Delete a picture on file system
        /// </summary>
        /// <param name="picture">Picture</param>
        private void DeletePictureOnFileSystem(Picture picture)
        {
            if (picture == null)
                throw new ArgumentNullException("picture");

            string[] parts = picture.MimeType.Split('/');
            string lastPart = parts[parts.Length - 1];
            switch (lastPart)
            {
                case "pjpeg":
                    lastPart = "jpg";
                    break;
                case "x-png":
                    lastPart = "png";
                    break;
                case "x-icon":
                    lastPart = "ico";
                    break;
            }
            string localFilename = string.Format("{0}_0.{1}", picture.Id.ToString("0000000"), lastPart);
            string localFilepath = Path.Combine(LocalImagePath, localFilename);
            if (File.Exists(localFilepath))
            {
                File.Delete(localFilepath);
            }
        }
开发者ID:cmcginn,项目名称:StoreFront,代码行数:30,代码来源:PictureService.cs

示例15: DeletePictureThumbs

 /// <summary>
 /// Delete picture thumbs
 /// </summary>
 /// <param name="picture">Picture</param>
 protected virtual void DeletePictureThumbs(Picture picture)
 {
     string filter = string.Format("{0}*.*", picture.Id.ToString("0000000"));
     var thumbDirectoryPath = _webHelper.MapPath("~/content/images/thumbs");
     string[] currentFiles = System.IO.Directory.GetFiles(thumbDirectoryPath, filter, SearchOption.AllDirectories);
     foreach (string currentFileName in currentFiles)
     {
         var thumbFilePath = GetThumbLocalPath(currentFileName);
         File.Delete(thumbFilePath);
     }
 }
开发者ID:chamithdev,项目名称:AntiquesWeb,代码行数:15,代码来源:PictureService.cs


注:本文中的Nop.Core.Domain.Media.Picture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。