📄 galleryimage.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CommunityServer.Components;
using CommunityServer.Galleries.Components;
namespace CommunityServer.Galleries.Controls
{
public class GalleryImage : Control
{
#region Protected Members
protected GalleryImageSettings settings = new GalleryImageSettings();
protected GalleryImageSettings secondarySettings = new GalleryImageSettings();
protected string imageIDprefix = "SmallThumb";
#endregion
#region Public Properties
private GalleryImageType imageType = GalleryImageType.Thumbnail;
public GalleryImageType ImageType
{
get { return imageType; }
set { imageType = value; }
}
[DefaultValue( "" )]
private string imageUrl = string.Empty;
public string ImageUrl
{
get { return imageUrl; }
set { imageUrl = value; }
}
[DefaultValue( "" )]
private string secondaryImageUrl = string.Empty;
public string SecondaryImageUrl
{
get { return secondaryImageUrl; }
set { secondaryImageUrl = value; }
}
[DefaultValue( "" )]
private string navigateUrl = string.Empty;
public string NavigateUrl
{
get { return navigateUrl; }
set { navigateUrl = value; }
}
[DefaultValue( false )]
private bool enableSecondaryThumbnail = false;
public bool EnableSecondaryThumbnail
{
get { return enableSecondaryThumbnail; }
set { enableSecondaryThumbnail = value; }
}
[DefaultValue( -1 )]
private int postID = -1;
public int PostID
{
get { return postID; }
set
{
postID = value;
picture = null;
}
}
[DefaultValue( true )]
private bool usePhotoCache = true;
public bool UsePhotoCache
{
get { return usePhotoCache; }
set { usePhotoCache = value; }
}
[DefaultValue( 0 )]
private int border = 0;
public int Border
{
get { return border; }
set { border = value; }
}
private string cssClass = string.Empty;
public string CssClass
{
get { return cssClass; }
set { cssClass = value; }
}
private string style = string.Empty;
public string Style
{
get { return style; }
set { style = value; }
}
private int width = 100;
public int Width
{
get { return width; }
set { width = value; }
}
private int height = 75;
public int Height
{
get { return height; }
set { height = value; }
}
private int quality = 70;
public int Quality
{
get { return quality; }
set { quality = value; }
}
private Picture picture = null;
public Picture Picture
{
get { return picture; }
set
{
picture = value;
if(picture != null)
postID = picture.PostID;
}
}
#endregion
#region Constructor
public GalleryImage() { }
public GalleryImage(GalleryImageType imageType) : this()
{
this.ImageType = imageType;
}
public GalleryImage(GalleryImageType imageType, Picture picture)
{
this.ImageType = imageType;
this.Picture = picture;
}
#endregion
#region Methods
protected virtual void LoadPicture()
{
if(picture == null)
{
if(postID != -1)
Picture = Pictures.GetPicture(PostID);
else if(CSContext.Current.PostID != -1)
Picture = Pictures.GetPicture(CSContext.Current.PostID);
}
}
public virtual void ProcessPicture()
{
// If there is no PostID, then there is nothing to process, return;
LoadPicture();
if(ImageType == GalleryImageType.Folder)
picture = new Picture();
if(picture == null)
return;
// If this is not an image, turn off the large thumbnail popups
if(EnableSecondaryThumbnail && !picture.ContentType.StartsWith("image"))
EnableSecondaryThumbnail = false;
// Find out which image type, put in the default settings, and scale it
if(picture.IsPicture)
{
switch(ImageType)
{
case GalleryImageType.Micro:
settings = new GalleryImageSettings(((Gallery)picture.Section).ThumbnailX, ((Gallery)picture.Section).ThumbnailY , ((Gallery)picture.Section).ThumbnailQuality, true, false, false);
settings.Brightness = ((Gallery)picture.Section).ThumbnailBrightness;
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, ImageType);
break;
case GalleryImageType.Gallery:
settings = new GalleryImageSettings(((Gallery)picture.Section).SecondaryThumbnailX, ((Gallery)picture.Section).SecondaryThumbnailY, ((Gallery)picture.Section).SecondaryThumbnailQuality, true, false, false);
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, ImageType);
break;
case GalleryImageType.Original:
settings.OriginalSize = true;
break;
case GalleryImageType.Thumbnail:
if(EnableSecondaryThumbnail)
{
secondarySettings = new GalleryImageSettings(((Gallery)picture.Section).SecondaryThumbnailX, ((Gallery)picture.Section).SecondaryThumbnailY, ((Gallery)picture.Section).SecondaryThumbnailQuality, true, false, false);
ScalePicture(GalleryImageType.SecondaryThumbnail, secondarySettings);
if(secondarySettings.OriginalSize == false)
SecondaryImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, GalleryImageType.SecondaryThumbnail);
else
SecondaryImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID);
}
settings = new GalleryImageSettings(((Gallery)picture.Section).ThumbnailX, ((Gallery)picture.Section).ThumbnailY, ((Gallery)picture.Section).ThumbnailQuality, true, false, false);
settings.Brightness = ((Gallery)picture.Section).ThumbnailBrightness;
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, ImageType);
break;
case GalleryImageType.SecondaryThumbnail:
settings = new GalleryImageSettings(((Gallery)picture.Section).SecondaryThumbnailX, ((Gallery)picture.Section).SecondaryThumbnailY, ((Gallery)picture.Section).SecondaryThumbnailQuality, true, false, false);
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, ImageType);
break;
case GalleryImageType.Details:
settings = new GalleryImageSettings(((Gallery)picture.Section).PictureDetailsX, ((Gallery)picture.Section).PictureDetailsY, ((Gallery)picture.Section).PictureDetailsQuality, true, false, false);
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, settings.Width, settings.Height);
break;
case GalleryImageType.Folder:
settings.Width = 60;
settings.Height = 56;
string path = GalleryUrls.Instance().Home;
path = path.Substring(0, path.LastIndexOf("/"));
ImageUrl = path + "/default_highlight_image.gif";
break;
case GalleryImageType.Slideshow:
settings = new GalleryImageSettings(((Gallery)picture.Section).SlideshowX, ((Gallery)picture.Section).SlideshowY, ((Gallery)picture.Section).SlideshowQuality, true, false, false);
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, settings.Width, settings.Height);
break;
case GalleryImageType.Other:
settings = new GalleryImageSettings(width, height, quality, true);
ScalePicture();
if(settings.OriginalSize == false)
ImageUrl = GalleryUrls.Instance().PictureUrl(((Gallery)picture.Section).ApplicationKey, picture.PostID, settings.Width, settings.Height);
break;
default:
ImageUrl = "";
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -