本文整理汇总了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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例7: PictureResult
public PictureResult(Picture picture, int targetSize)
: base(GetMemoryStream(picture, targetSize), picture.MimeType)
{
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}