public override void GetUrl(ImageParameters properties, OnUrlComplete onComplete) { Envelope extent = properties.Extent; int width = properties.Width; int height = properties.Height; int num = (extent.SpatialReference != null) ? extent.SpatialReference.WKID : 0; width = Math.Min(width, 1024); height = Math.Min(height, 1024); // zoom 范围3-19 double offset = Math.Max(Math.Abs(extent.XMax - extent.XMin), Math.Abs(extent.YMax - extent.YMin)); double zoom = Convert.ToInt32(Math.Log(offset / 2880, 0.5)); if (zoom < 3) { zoom = 3; } else if (zoom > 19) { zoom = 19; } onComplete(string.Format(urlFormat, extent.GetCenter().X, extent.GetCenter().Y, width, height, zoom), new DynamicLayer.ImageResult(new Envelope { XMin = extent.XMin, YMin = extent.YMin, XMax = extent.XMax, YMax = extent.YMax })); }
protected void Page_PreRender(object sender, EventArgs e) { ImageParameters imgParams = new ImageParameters(); if (!String.IsNullOrEmpty(URL)) { imgParams.Url = ResolveUrl(URL); } imgParams.Align = Align; imgParams.Alt = Alt; imgParams.Behavior = Behavior; imgParams.BorderColor = BorderColor; imgParams.BorderWidth = BorderWidth; imgParams.Class = Class; imgParams.Extension = Extension; imgParams.Height = Height; imgParams.HSpace = HSpace; imgParams.Id = (String.IsNullOrEmpty(ImageID) ? Guid.NewGuid().ToString() : ImageID); imgParams.Link = Link; imgParams.SizeToURL = SizeToURL; imgParams.Style = Style; imgParams.Target = Target; imgParams.Tooltip = Tooltip; imgParams.VSpace = VSpace; imgParams.Width = Width; ltlImage.Text = MediaHelper.GetImage(imgParams); }
private Stream EncodeBitmap(Bitmap1 bitmap, Guid containerFormat) { using (var bitmapEncoder = new BitmapEncoder(WicFactory, containerFormat)) { var memoryStream = new MemoryStream(); bitmapEncoder.Initialize(memoryStream); using (var frameEncode = new BitmapFrameEncode(bitmapEncoder)) { frameEncode.Initialize(); var wicPixelFormat = ImagePixelFormat; frameEncode.SetPixelFormat(ref wicPixelFormat); var imageParams = new ImageParameters() { PixelFormat = DevicePixelFormat, DpiX = Dpi, DpiY = Dpi, PixelWidth = bitmap.PixelSize.Width, PixelHeight = bitmap.PixelSize.Height }; WicImageEncoder.WriteFrame(bitmap, frameEncode, imageParams); frameEncode.Commit(); bitmapEncoder.Commit(); } memoryStream.Position = 0; return(memoryStream); } }
private (long width, long height) GetImageSizeInEmu(byte[] data, ImageParameters imageParameters) { if (data.Length == 0) { return(0, 0); } long pixelWidth; long pixelHeight; using (var ms = new MemoryStream(data)) { var image = Image.FromStream(ms); _logger.LogInformation("Image size in pixels: {0}x{1}", image.Width, image.Height); pixelWidth = image.Width.PxToEmu(); pixelHeight = image.Height.PxToEmu(); _logger.LogInformation("Image size in emu: {0}x{1}", pixelWidth, pixelHeight); } var(width, height) = imageParameters.Scale(pixelWidth, pixelHeight); _logger.LogInformation("Scaled image size in emu: {0}x{1}", width, height); return(width, height); }
public override void DrawImage(ImageParameters parms) { //uint[] gtexture = new uint[1]; //System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, parms.Image.Width, parms.Image.Height); //System.Drawing.Imaging.BitmapData gbitmapdata = parms.Image.Bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); //parms.Image.Bitmap.UnlockBits(gbitmapdata); //_openGL.GenTextures(1, gtexture); //_openGL.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]); //_openGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGB8, parms.Image.Bitmap.Width, parms.Image.Bitmap.Height, 0, OpenGL.GL_BGR_EXT, OpenGL.GL_UNSIGNED_BYTE, gbitmapdata.Scan0); //uint[] array = new uint[] { OpenGL.GL_NEAREST }; //_openGL.TexParameterI(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, array); //_openGL.TexParameterI(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, array); //_openGL.Enable(OpenGL.GL_TEXTURE_2D); //_openGL.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]); //_openGL.Color(1.0f, 1.0f, 1.0f, 0.1f); //Must have, weirdness! //_openGL.Begin(OpenGL.GL_QUADS); //_openGL.TexCoord(1.0f, 1.0f); //_openGL.Vertex(parms.Width ?? parms.Image.Width, parms.Height ?? parms.Image.Height, 1.0f); //_openGL.TexCoord(0.0f, 1.0f); //_openGL.Vertex(0.0f, parms.Height ?? parms.Image.Height, 1.0f); //_openGL.TexCoord(0.0f, 0.0f); //_openGL.Vertex(0.0f, 0.0f, 1.0f); //_openGL.TexCoord(1.0f, 0.0f); //_openGL.Vertex(parms.Width ?? parms.Image.Width, 0.0f, 1.0f); //_openGL.End(); //_openGL.Disable(OpenGL.GL_TEXTURE_2D); }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <typeparam name="T">The model type</typeparam> /// <param name="model">The model that contains the image field</param> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual RawString RenderImage <T>(T model, Expression <Func <T, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(_glassHtml.RenderImage(model, field, parameters, isEditable).RawString()); }
public static FrameSize CalculateImagePreviewSize(ImageParameters param, int maxWidth, int maxHeight = int.MaxValue) { var bounds = param.CropBounds; var w = (int)Math.Max(Math.Round((bounds.Right - bounds.Left) / param.Scale), 0); var h = (int)Math.Max(Math.Round((bounds.Bottom - bounds.Top) / param.Scale), 0); return(CalculateImagePreviewSize(w, h, maxWidth, maxHeight)); }
public static GLTexture2DArray FromGeneric(STGenericTexture texture, ImageParameters parameters) { GLTexture2DArray glTexture = new GLTexture2DArray(); glTexture.Width = (int)texture.Width; glTexture.Height = (int)texture.Height; glTexture.LoadImage(texture, parameters); return(glTexture); }
public async Task <SearchImage> GetImageDetails(ImageParameters imageParameters) { var searchimage = new SearchImage(); var result = await Urls.GetStringAsync(Urls.BaseUri + "photos/" + imageParameters.PhotoID + "?client_id=" + Urls.client_id + "&client_secret=" + Urls.client_secret + "&v=20190425"); var result_image = JsonConvert.DeserializeObject <SearchImage>(result); return(result_image); }
private ImageParameters ImageParameters(JToken token) { var image = new ImageParameters { Name = token["n"].Value<string>(), Size = token["s"].Value<long>() }; return image; }
public static GLTexture3D FromGeneric(STGenericTexture texture, ImageParameters parameters) { GLTexture3D glTexture = new GLTexture3D(); glTexture.Target = TextureTarget.Texture3D; glTexture.Width = (int)texture.Width; glTexture.Height = (int)texture.Height; glTexture.LoadImage(texture, parameters); return(glTexture); }
private ImageParameters ImageParameters(JToken token) { var image = new ImageParameters { Name = token["n"].Value <string>(), Size = token["s"].Value <long>() }; return(image); }
private Image Image(Node node) { var image = new ImageParameters { Name = node.Name, Size = node.SizeAsBytes() }; return(Media <ImageParameters> .Create <Image>(image, this)); }
private Image Image(Node node) { var image = new ImageParameters { Name = node.Name, Size = node.SizeAsBytes() }; return Media<ImageParameters>.Create<Image>(image, this); }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <typeparam name="T">The model type</typeparam> /// <param name="model">The model that contains the image field</param> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual string RenderImage <T>(T model, Expression <Func <T, object> > field, ImageParameters parameters = null, bool isEditable = false) { if (IsInEditingMode && isEditable) { return(Editable(model, field, parameters)); } else { return(RenderImage(field.Compile().Invoke(model) as Fields.Image, parameters == null ? null : parameters.Parameters)); } }
public void InsertImage(int width, int height, int ascent, VerticalCharacterAlignment verticalAlign, string alternateText, string filename) { var image = new ImageParameters { xWidth = width, yHeight = height, ascent = ascent, type = (int)verticalAlign, pwszAlternateText = alternateText, pIStream = NativeMethods.SHCreateStreamOnFileEx(filename, (int)0x00000040L, 0x1, false, null) }; NativeMethods.SendMessage(Handle, RichEditMessages.EM_INSERTIMAGE, IntPtr.Zero, ref image); }
public static GLTexture2D FromGeneric(STGenericTexture texture, ImageParameters parameters = null) { if (parameters == null) { parameters = new ImageParameters(); } GLTexture2D glTexture = new GLTexture2D(); glTexture.Target = TextureTarget.Texture2D; glTexture.Width = (int)texture.Width; glTexture.Height = (int)texture.Height; glTexture.LoadImage(texture, parameters); return(glTexture); }
/// <summary> /// Creates the image object /// </summary> private void CreateImage() { ImageParameters imgParams = new ImageParameters(); if (Url != null) { imgParams.Url = URLHelper.GetAbsoluteUrl(Url); imgParams.Extension = Type; imgParams.Width = Width; imgParams.Height = Height; imgParams.Id = HttpUtility.UrlDecode(Id); imgParams.Tooltip = HttpUtility.UrlDecode(Title); imgParams.Class = HttpUtility.UrlDecode(Class); imgParams.Style = HttpUtility.UrlDecode(Style); } ltlMedia.Text = MediaHelper.GetImage(imgParams); }
public Run AddImage(ImageModel model, string parameters) { var imagePartType = model.ImageName.ImagePartTypeFromName(); var imagePart = _mainDocumentPart.AddImagePart(imagePartType); using (var ms = new MemoryStream(model.Data)) { imagePart.FeedData(ms); } _logger.LogInformation("Image parameters string: {0}", parameters); var ip = ImageParameters.FromString(parameters); _logger.LogInformation("Image parameters in emu: {0}", ip.ToString()); var(width, height) = this.GetImageSizeInEmu(model.Data, ip); var run = this.CreateRun(model.ImageName, _mainDocumentPart.GetIdOfPart(imagePart), width, height); return(run); }
public static GLTexture FromGenericTexture(STGenericTexture texture, ImageParameters parameters = null) { if (parameters == null) { parameters = new ImageParameters(); } switch (texture.SurfaceType) { case STSurfaceType.Texture2D_Array: return(GLTexture2DArray.FromGeneric(texture, parameters)); case STSurfaceType.Texture3D: return(GLTexture3D.FromGeneric(texture, parameters)); case STSurfaceType.TextureCube: return(GLTextureCube.FromGeneric(texture, parameters)); default: return(GLTexture2D.FromGeneric(texture, parameters)); } }
public override void DrawImage(ImageParameters parms) { using (DeviceContextHandler dch = GetDeviceContextHandler()) { try { Rectangle rect = Style.GetAdjustedRectangle(parms); if (!Style.TintParameters.Disabled) { dch.DrawingSurface.DrawImage(parms.Image.Bitmap, rect.SystemRectangle, 0, 0, parms.Image.Width, parms.Image.Height, GraphicsUnit.Pixel, Style.TintParameters.ImageAttributes); } else { dch.DrawingSurface.DrawImage(parms.Image.Bitmap, rect.SystemRectangleF); } } catch (Exception e) { Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } } }
public void RenderImage_ValidImageWithWidthAndStretcj_RendersCorrectHtml() { //Arrange var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?w=900&as=True' alt='someAlt' width='900' />"; var scContext = Substitute.For <ISitecoreContext>(); var html = new GlassHtml(scContext); var image = new Fields.Image(); image.Alt = "someAlt"; image.Width = 200; image.Height = 105; image.Src = "~/media/Images/Carousel/carousel-example.ashx"; var parameters = new ImageParameters { Width = 900, AllowStretch = true }; var model = new { Image = image }; //Act var result = html.RenderImage(model, x => x.Image, parameters, true); //Assert Assert.AreEqual(expected, result); }
public void Read(FileReader reader) { //Magic and ID not pointed to for sub entries so just skip them for now // uint magic = reader.ReadUInt32(); // if (magic != Identifier) // throw new Exception($"Invalid texture header magic! Expected {Identifier.ToString("x")}. Got {Identifier.ToString("x")}"); // ID = reader.ReadUInt32(); PlatformSwizzle = PlatformSwizzle.Platform_3DS; ImageSize = reader.ReadUInt32(); ID2 = reader.ReadUInt32(); reader.Seek(0x8); Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); reader.Seek(3); var numMips = reader.ReadByte(); reader.Seek(0x14); byte FormatCtr = reader.ReadByte(); reader.Seek(3); MipCount = 1; Format = CTR_3DS.ConvertPICAToGenericFormat((CTR_3DS.PICASurfaceFormat)FormatCtr); Parameters = new ImageParameters(); Parameters.FlipY = true; properties = new POWEProperties(); properties.ID = ID2; properties.Width = Width; properties.Height = Height; properties.NumMips = numMips; properties.Format = Format; }
/* Settign parameter value */ public void setParameter(ImageParameters param, double value) { int paramIndex = (int)param; _parameterVector[paramIndex] = value; }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <typeparam name="T">The model type</typeparam> /// <param name="model">The model that contains the image field</param> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual string RenderImage(Expression <Func <T, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(base.RenderImage(this.Model, field, parameters, isEditable)); }
protected void Page_PreRender(object sender, EventArgs e) { if (Behavior == "hover") { StringBuilder sb = new StringBuilder(); // If jQuery not loaded sb.AppendFormat(@" if (typeof jQuery == 'undefined') {{ var jQueryCore=document.createElement('script'); jQueryCore.setAttribute('type','text/javascript'); jQueryCore.setAttribute('src', '{0}'); setTimeout('document.body.appendChild(jQueryCore)',100); setTimeout('loadTooltip()',200); }}", ScriptHelper.GetScriptUrl("~/CMSScripts/jquery/jquery-core.js")); // If jQuery tooltip plugin not loaded sb.AppendFormat(@" var jQueryTooltips=document.createElement('script'); function loadTooltip() {{ if (typeof jQuery == 'undefined') {{ setTimeout('loadTooltip()',200); return;}} if (typeof jQuery.fn.tooltip == 'undefined') {{ jQueryTooltips.setAttribute('type','text/javascript'); jQueryTooltips.setAttribute('src', '{0}'); setTimeout('document.body.appendChild(jQueryTooltips)',100); }} }}", ScriptHelper.GetScriptUrl("~/CMSScripts/jquery/jquery-tooltips.js")); string rtlDefinition = null; if (((IsLiveSite) && (CultureHelper.IsPreferredCultureRTL())) || (CultureHelper.IsUICultureRTL())) { rtlDefinition = "positionLeft: true,left: -15,"; } sb.AppendFormat(@" function hover(imgID, width, height, sizeInUrl) {{ if ((typeof jQuery == 'undefined')||(typeof jQuery.fn.tooltip == 'undefined')) {{ var imgIDForTimeOut = imgID.replace(/\\/gi,""\\\\"").replace(/'/gi,""\\'""); setTimeout(""loadTooltip();hover('""+imgIDForTimeOut+""',""+width+"",""+height+"",""+sizeInUrl+"")"",100); return; }} jQuery('img[id='+imgID+']').tooltip({{ delay: 0, track: true, showBody: "" - "", showBody: "" - "", extraClass: ""ImageExtraClass"", showURL: false, {0} bodyHandler: function() {{ var hidden = jQuery(""#"" + imgID + ""_src""); var source = this.src; if (hidden[0] != null) {{ source = hidden[0].value; }} var hoverDiv = jQuery(""<div/>""); var hoverImg = jQuery(""<img/>"").attr(""class"", ""ImageTooltip"").attr(""src"", source); hoverImg.css({{'width' : width, 'height' : height}}); hoverDiv.append(hoverImg); return hoverDiv; }} }}); }}", rtlDefinition); ScriptHelper.RegisterStartupScript(Page, typeof(Page), "JQueryImagePreview", ScriptHelper.GetScript(sb.ToString())); } ImageParameters imgParams = new ImageParameters(); if (!String.IsNullOrEmpty(URL)) { imgParams.Url = ResolveUrl(URL); } imgParams.Align = Align; imgParams.Alt = Alt; imgParams.Behavior = Behavior; imgParams.BorderColor = BorderColor; imgParams.BorderWidth = BorderWidth; imgParams.Class = Class; imgParams.Extension = Extension; imgParams.Height = Height; imgParams.HSpace = HSpace; imgParams.Id = (String.IsNullOrEmpty(ImageID) ? Guid.NewGuid().ToString() : ImageID); imgParams.Link = Link; imgParams.MouseOverHeight = MouseOverHeight; imgParams.MouseOverWidth = MouseOverWidth; imgParams.SizeToURL = SizeToURL; imgParams.Style = Style; imgParams.Target = Target; imgParams.Tooltip = Tooltip; imgParams.VSpace = VSpace; imgParams.Width = Width; if (ShowFileIcons && (Extension != null)) { imgParams.Width = 0; imgParams.Height = 0; imgParams.Url = GetFileIconUrl(Extension, "List"); } ltlImage.Text = MediaHelper.GetImage(imgParams); // Dynamic JQuery hover effect if (Behavior == "hover") { string imgId = HTMLHelper.HTMLEncode(HttpUtility.UrlDecode(imgParams.Id)); string url = HttpUtility.HtmlDecode(URL); if (SizeToURL) { if (MouseOverWidth > 0) { url = URLHelper.UpdateParameterInUrl(url, "width", MouseOverWidth.ToString()); } if (MouseOverHeight > 0) { url = URLHelper.UpdateParameterInUrl(url, "height", MouseOverHeight.ToString()); } url = URLHelper.RemoveParameterFromUrl(url, "maxsidesize"); } ltlImage.Text += "<input type=\"hidden\" id=\"" + imgId + "_src\" value=\"" + ResolveUrl(url) + "\" />"; ScriptHelper.RegisterStartupScript(Page, typeof(Page), "ImageHover_" + imgId, ScriptHelper.GetScript("hover(" + ScriptHelper.GetString(ScriptHelper.EscapeJQueryCharacters(imgId)) + ", " + MouseOverWidth + ", " + MouseOverHeight + ", " + (SizeToURL ? "true" : "false") + ");")); if (!RequestStockHelper.Contains("DialogsImageHoverStyle")) { RequestStockHelper.Add("DialogsImageHoverStyle", true); CSSHelper.RegisterCSSBlock(Page, "#tooltip {position: absolute;z-index:5000;}"); } } }
/// <summary> /// Initializes the control properties. /// </summary> public void ReloadData(bool forceReload) { if (binded && !forceReload) { return; } if (mData != null) { MediaFileInfo mfi = new MediaFileInfo(mData); SiteInfo currentSite = SiteContext.CurrentSite; SiteInfo si = mfi.FileSiteID == currentSite.SiteID ? currentSite : SiteInfo.Provider.Get(mfi.FileSiteID); if (si != null) { if (DisplayActiveContent) { string url = ""; // Complete URL only for other site than current bool completeUrl = (si.SiteID != currentSite.SiteID); if (UseSecureLinks) { string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension); url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName) : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName); } else { MediaLibraryInfo li = MediaLibraryInfo.Provider.Get(mfi.FileLibraryID); if (li != null) { url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath) : MediaFileURLProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } } url = UrlResolver.ResolveUrl(url); if (ImageHelper.IsImage(mfi.FileExtension) && File.Exists(MediaFileInfoProvider.GetMediaFilePath(mfi.FileLibraryID, mfi.FilePath))) { // Get new dimensions int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mfi.FileImageWidth, mfi.FileImageHeight); // If dimensions changed use secure link if ((newDims[0] != mfi.FileImageWidth) || (newDims[1] != mfi.FileImageHeight)) { string fileName = AttachmentHelper.GetFullFileName(mfi.FileName, mfi.FileExtension); url = completeUrl ? MediaFileURLProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, fileName) : MediaFileURLProvider.GetMediaFileUrl(mfi.FileGUID, fileName); url = UrlResolver.ResolveUrl(url); } else { // Use width and height from properties in case dimensions are bigger than original newDims[0] = Width; newDims[1] = Height; } // Initialize image parameters ImageParameters imgParams = new ImageParameters(); imgParams.Alt = mfi.FileDescription; imgParams.Width = newDims[0]; imgParams.Height = newDims[1]; imgParams.Url = url; ltlOutput.Text = MediaHelper.GetImage(imgParams); } else if (MediaHelper.IsAudioVideo(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters audioVideoParams = new AudioVideoParameters(); audioVideoParams.SiteName = SiteContext.CurrentSiteName; audioVideoParams.Url = url; audioVideoParams.Width = Width; audioVideoParams.Height = Height; audioVideoParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(audioVideoParams); } else { ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } else { ltlOutput.Text = ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page); } } } binded = true; }
public UndoHelper(ImageParameters img) { this.img = img; }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual IEncodedString RenderImage(Expression <Func <TModel, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(GlassHtml.RenderImage(Model, field, parameters, isEditable)); }
/* Return an given parameter of current vector */ public double getParameter(ImageParameters param) { int paramIndex = (int)param; return _parameterVector[paramIndex]; }
/// <summary> /// Creates the image object /// </summary> private void CreateImage() { ImageParameters imgParams = new ImageParameters(); if (this.Url != null) { imgParams.Url = URLHelper.GetAbsoluteUrl(this.Url); imgParams.Extension = this.Type; imgParams.Width = this.Width; imgParams.Height = this.Height; imgParams.Id = HttpUtility.UrlDecode(this.Id); imgParams.Tooltip = HttpUtility.UrlDecode(this.Title); imgParams.Class = HttpUtility.UrlDecode(this.Class); imgParams.Style = HttpUtility.UrlDecode(this.Style); } this.ltlMedia.Text = MediaHelper.GetImage(imgParams); }
/// <summary> /// Renders an image allowing simple page editor support /// </summary> /// <typeparam name="T">The model type</typeparam> /// <param name="model">The model that contains the image field</param> /// <param name="field">A lambda expression to the image field, should be of type Glass.Mapper.Sc.Fields.Image</param> /// <param name="parameters">Image parameters, e.g. width, height</param> /// <param name="isEditable">Indicates if the field should be editable</param> /// <returns></returns> public virtual HtmlString RenderImage <T>(T target, Expression <Func <T, object> > field, ImageParameters parameters = null, bool isEditable = false) { return(new HtmlString(GlassHtml.RenderImage <T>(target, field, parameters, isEditable))); }
/// <summary> /// Initializes the control properties. /// </summary> public void ReloadData(bool forceReload) { if (!binded || forceReload) { if (this.mData != null) { MediaFileInfo mfi = new MediaFileInfo(this.mData); if (mfi != null) { bool completeUrl = false; // Get the site SiteInfo si = null; SiteInfo currentSite = CMSContext.CurrentSite; if (mfi.FileSiteID == currentSite.SiteID) { si = currentSite; } else { si = SiteInfoProvider.GetSiteInfo(mfi.FileSiteID); } if (si != null) { // Complete URL only for other site than current if (si.SiteID != currentSite.SiteID) { completeUrl = true; } string url = ""; if (this.UseSecureLinks) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } else { MediaLibraryInfo li = MediaLibraryInfoProvider.GetMediaLibraryInfo(mfi.FileLibraryID); if (li != null) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } else { url = MediaFileInfoProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } } } if (this.DisplayActiveContent) { if (ImageHelper.IsImage(mfi.FileExtension) && File.Exists(MediaFileInfoProvider.GetMediaFilePath(mfi.FileLibraryID, mfi.FilePath))) { // Get new dimensions int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mfi.FileImageWidth, mfi.FileImageHeight); // If dimensions changed use secure link if ((newDims[0] != mfi.FileImageWidth) || (newDims[1] != mfi.FileImageHeight)) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } else { // Use width and height from properties in case dimensions are bigger than original newDims[0] = Width; newDims[1] = Height; } // Initialize image parameters ImageParameters imgParams = new ImageParameters(); imgParams.Alt = mfi.FileDescription; imgParams.Width = newDims[0]; imgParams.Height = newDims[1]; imgParams.Url = url; this.ltlOutput.Text = CMS.GlobalHelper.MediaHelper.GetImage(imgParams); } else if (CMS.GlobalHelper.MediaHelper.IsFlash(mfi.FileExtension)) { // Initialize flash parameters FlashParameters flashParams = new FlashParameters(); flashParams.Url = url; flashParams.Width = this.Width; flashParams.Height = this.Height; this.ltlOutput.Text = CMS.GlobalHelper.MediaHelper.GetFlash(flashParams); } else if (CMS.GlobalHelper.MediaHelper.IsAudio(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters audioParams = new AudioVideoParameters(); audioParams.SiteName = CMSContext.CurrentSiteName; audioParams.Url = url; audioParams.Width = this.Width; audioParams.Height = this.Height; audioParams.Extension = mfi.FileExtension; this.ltlOutput.Text = CMS.GlobalHelper.MediaHelper.GetAudioVideo(audioParams); } else if (CMS.GlobalHelper.MediaHelper.IsVideo(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters videoParams = new AudioVideoParameters(); videoParams.SiteName = CMSContext.CurrentSiteName; videoParams.Url = url; videoParams.Width = this.Width; videoParams.Height = this.Height; videoParams.Extension = mfi.FileExtension; this.ltlOutput.Text = CMS.GlobalHelper.MediaHelper.GetAudioVideo(videoParams); } else { this.ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, this.Width, this.Height, this.MaxSideSize, this.PreviewSuffix, this.IconSet, this.Page, this.DefaultImageUrl); } } else { this.ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, this.Width, this.Height, this.MaxSideSize, this.PreviewSuffix, this.IconSet, this.Page, this.DefaultImageUrl); } } } } binded = true; } }
/// <summary> /// Decodes a byte array of image data given the source image in bytes, width, height, and DXGI format. /// </summary> /// <param name="byte[]">The byte array of the image</param> /// <param name="Width">The width of the image in pixels.</param> /// <param name="Height">The height of the image in pixels.</param> /// <param name=" DDS.DXGI_FORMAT">The image format.</param> /// <returns>Returns a byte array of decoded data. </returns> public static byte[] DecodeBlock(byte[] data, uint Width, uint Height, TEX_FORMAT Format, byte[] paletteData, ImageParameters parameters, PALETTE_FORMAT PaletteFormat = PALETTE_FORMAT.None, PlatformSwizzle PlatformSwizzle = PlatformSwizzle.None) { if (data == null) { throw new Exception($"Data is null!"); } if (Format <= 0) { throw new Exception($"Invalid Format!"); } if (data.Length <= 0) { throw new Exception($"Data is empty!"); } if (Width <= 0) { throw new Exception($"Invalid width size {Width}!"); } if (Height <= 0) { throw new Exception($"Invalid height size {Height}!"); } byte[] imageData = new byte[0]; bool DontSwapRG = false; if (PlatformSwizzle == PlatformSwizzle.Platform_3DS) { imageData = CTR_3DS.DecodeBlock(data, (int)Width, (int)Height, Format); DontSwapRG = true; } else if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube) { imageData = Decode_Gamecube.DecodeData(data, paletteData, Width, Height, Format, PaletteFormat); } else { if (Format == TEX_FORMAT.R32G8X24_FLOAT) { imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS); } if (Format == TEX_FORMAT.BC5_SNORM) { imageData = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true); } if (Format == TEX_FORMAT.L8) { return(RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format)); } if (Format == TEX_FORMAT.LA8) { return(RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format)); } if (Format == TEX_FORMAT.R5G5B5A1_UNORM) { return(RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format)); } if (IsCompressed(Format)) { imageData = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); } else { if (IsAtscFormat(Format)) { imageData = ASTCDecoder.DecodeToRGBA8888(data, (int)GetBlockWidth(Format), (int)GetBlockHeight(Format), 1, (int)Width, (int)Height, 1); } else { imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); } // imageData = RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format); } } if (parameters.DontSwapRG || DontSwapRG) { return(imageData); } else { return(ConvertBgraToRgba(imageData)); } }
protected void Page_PreRender(object sender, EventArgs e) { if (Behavior == "hover") { StringBuilder sb = new StringBuilder(); // If jQuery not loaded sb.AppendFormat(@" if (typeof $cmsj == 'undefined') {{ var jQueryCore=document.createElement('script'); jQueryCore.setAttribute('type','text/javascript'); jQueryCore.setAttribute('src', '{0}'); setTimeout('document.body.appendChild(jQueryCore)',100); setTimeout('loadTooltip()',200); }}", ScriptHelper.GetScriptUrl("~/CMSScripts/jquery/jquery-core.js")); // If jQuery tooltip plugin not loaded sb.AppendFormat(@" var jQueryTooltips=document.createElement('script'); function loadTooltip() {{ if (typeof $cmsj == 'undefined') {{ setTimeout('loadTooltip()',200); return;}} if (typeof $cmsj.fn.tooltip == 'undefined') {{ jQueryTooltips.setAttribute('type','text/javascript'); jQueryTooltips.setAttribute('src', '{0}'); setTimeout('document.body.appendChild(jQueryTooltips)',100); }} }}", ScriptHelper.GetScriptUrl("~/CMSScripts/jquery/jquery-tooltips.js")); string rtlDefinition = null; if (((IsLiveSite) && (CultureHelper.IsPreferredCultureRTL())) || (CultureHelper.IsUICultureRTL())) { rtlDefinition = "positionLeft: true,left: -15,"; } sb.AppendFormat(@" function hover(imgID, width, height, sizeInUrl) {{ if ((typeof $cmsj == 'undefined')||(typeof $cmsj.fn.tooltip == 'undefined')) {{ var imgIDForTimeOut = imgID.replace(/\\/gi,""\\\\"").replace(/'/gi,""\\'""); setTimeout(""loadTooltip();hover('"" + imgIDForTimeOut + ""',"" + width + "","" +height + "","" + sizeInUrl + "")"",100); return; }} $cmsj('img[id=' + imgID + ']').tooltip({{ delay: 0, track: true, showBody: "" - "", showBody: "" - "", extraClass: ""ImageExtraClass"", showURL: false, {0} bodyHandler: function() {{ // Apply additional style to main hover div if needed $cmsj('#tooltip').css({{'position' : 'absolute','z-index' : 5000}}); var hidden = $cmsj(""#"" + imgID + ""_src""); var source = this.src; if (hidden[0] != null) {{ source = hidden[0].value; }} var hoverDiv = $cmsj(""<div/>""); var hoverImg = $cmsj(""<img/>"").attr(""class"", ""ImageTooltip"").attr(""src"", source); hoverImg.css({{'width' : width, 'height' : height}}); hoverDiv.append(hoverImg); return hoverDiv; }} }}); }}", rtlDefinition); ScriptHelper.RegisterStartupScript(Page, typeof(Page), "JQueryImagePreview", ScriptHelper.GetScript(sb.ToString())); } ImageParameters imgParams = new ImageParameters(); if (!String.IsNullOrEmpty(URL)) { imgParams.Url = ResolveUrl(URL); } imgParams.Align = Align; imgParams.Alt = Alt; imgParams.Behavior = Behavior; imgParams.BorderColor = BorderColor; imgParams.BorderWidth = BorderWidth; imgParams.Class = Class; imgParams.Extension = Extension; imgParams.Height = Height; imgParams.HSpace = HSpace; imgParams.Id = (String.IsNullOrEmpty(ImageID) ? Guid.NewGuid().ToString() : ImageID); imgParams.Link = Link; imgParams.MouseOverHeight = MouseOverHeight; imgParams.MouseOverWidth = MouseOverWidth; imgParams.SizeToURL = SizeToURL; imgParams.Style = Style; imgParams.Target = Target; imgParams.Tooltip = Tooltip; imgParams.VSpace = VSpace; imgParams.Width = Width; ltlImage.Text = MediaHelper.GetImage(imgParams); // Dynamic JQuery hover effect if (Behavior == "hover") { string imgId = HTMLHelper.HTMLEncode(HttpUtility.UrlDecode(imgParams.Id)); string url = HttpUtility.HtmlDecode(URL); if (SizeToURL) { if (MouseOverWidth > 0) { url = URLHelper.UpdateParameterInUrl(url, "width", MouseOverWidth.ToString()); } if (MouseOverHeight > 0) { url = URLHelper.UpdateParameterInUrl(url, "height", MouseOverHeight.ToString()); } url = URLHelper.RemoveParameterFromUrl(url, "maxsidesize"); } ltlImage.Text += "<input type=\"hidden\" id=\"" + imgId + "_src\" value=\"" + ResolveUrl(url) + "\" />"; ScriptHelper.RegisterStartupScript(Page, typeof(Page), "ImageHover_" + imgId, ScriptHelper.GetScript("hover(" + ScriptHelper.GetString(ScriptHelper.EscapeJQueryCharacters(imgId)) + ", " + MouseOverWidth + ", " + MouseOverHeight + ", " + (SizeToURL ? "true" : "false") + ");")); } }
/// <summary> /// Runs the RLHT over the image, skipping lines around uninteresting areas. /// </summary> /// <param name="Input">Input image segment.</param> /// <param name="ImP">Image-specific detection parameters.</param> /// <param name="AGD">Algorithm arguments.</param> /// <returns></returns> internal static HTResult SmartSkipRLHT(double[,] Input, ImageParameters ImP, AlgorithmData AGD) { /* Compute algorithm parameters */ int Height = Input.GetLength(0); int Width = Input.GetLength(1); double ThetaUnit = Min(Atan2(1, Height), Atan2(1, Width)); double NTheta = 2 * PI / ThetaUnit; double RhoMax = Sqrt(Width * Width + Height * Height); lock (AGD.HTPool) if (AGD.HTPool.Constructor == null) { AGD.HTPool.Constructor = () => new double[(int)Round(RhoMax), (int)Round(NTheta)]; } double[,] HTMatrix = AGD.HTPool.Acquire(); int NRd = HTMatrix.GetLength(0); int NTh = HTMatrix.GetLength(1); int i, j; List <Vector> HoughPowerul = AGD.VPool.Acquire(); double StrongHoughTh = AGD.StrongHoughThreshold; float[] FData = null; /* Initialize skip controlling variables */ int StrongHoughReset = 2 * AGD.ScanSkip + 1; /* Counter reset value, minimum to search Skip around found value */ int StrongHoughInnerCounter = 0; /* Inner loop counter */ int StrongHoughOuterCounter = 0; /* Outer loop counter */ bool StrongHough = false; /* For all distances */ for (i = 0; i < NRd; i++) { /* Any relevant coordinates? */ StrongHough = false; /* For all angles */ for (j = 0; j < NTh; j++) { /* Compute angle and skip irrelevant angles */ double Theta = j * ThetaUnit; if (Theta > PI / 2) { if (Theta < PI) { continue; } } /* Integrate along the line */ double Length; if (AGD.SimpleLine) { SimpleLineover(Input, Height, Width, i, Theta, ImP, out HTMatrix[i, j], out Length, ref FData, AGD.LineSkip); } else { Lineover(Input, Height, Width, i, Theta, ImP, out HTMatrix[i, j], out Length); } /* If has a function dependent on the length */ if (AGD.StrongValueFunction != null) { StrongHoughTh = AGD.StrongValueFunction(Length); } /* If relevant coordinates */ if (Length != 0 && HTMatrix[i, j] > StrongHoughTh) { HoughPowerul.Add(new Vector() { X = i, Y = Theta }); /* When new interesting coordinates, jump back and analyze */ if (StrongHoughInnerCounter == 0) { if (j > AGD.ScanSkip) { j -= AGD.ScanSkip; } else { j = 0; } } /* Reset counter and notify outer loop */ StrongHoughInnerCounter = StrongHoughReset; StrongHough = true; } /* If no interesting points, skip angles and decrement counter */ else { if (StrongHoughInnerCounter == 0) { j += AGD.ScanSkip - 1; } else { StrongHoughInnerCounter--; } } } /* If no interesting points, skip radii and decrement counter */ if (!StrongHough) { if (StrongHoughOuterCounter == 0) { i += AGD.ScanSkip - 1; } else { StrongHoughOuterCounter--; } } else { /* New interesting coordinates, jump back and analyze */ if (StrongHoughOuterCounter == 0) { if (i > AGD.ScanSkip) { i -= AGD.ScanSkip; } else { i = 0; } } /* Reset counter */ StrongHoughOuterCounter = StrongHoughReset; } } return(new HTResult() { StrongPoints = HoughPowerul, HTMatrix = HTMatrix }); }
/// <summary> /// Initializes the control properties. /// </summary> public void ReloadData(bool forceReload) { if (!binded || forceReload) { if (mData != null) { MediaFileInfo mfi = new MediaFileInfo(mData); if (mfi != null) { bool completeUrl = false; // Get the site SiteInfo si = null; SiteInfo currentSite = CMSContext.CurrentSite; if (mfi.FileSiteID == currentSite.SiteID) { si = currentSite; } else { si = SiteInfoProvider.GetSiteInfo(mfi.FileSiteID); } if (si != null) { // Complete URL only for other site than current if (si.SiteID != currentSite.SiteID) { completeUrl = true; } string url = ""; if (UseSecureLinks) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } else { MediaLibraryInfo li = MediaLibraryInfoProvider.GetMediaLibraryInfo(mfi.FileLibraryID); if (li != null) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } else { url = MediaFileInfoProvider.GetMediaFileUrl(si.SiteName, li.LibraryFolder, mfi.FilePath); } } } if (DisplayActiveContent) { if (ImageHelper.IsImage(mfi.FileExtension) && File.Exists(MediaFileInfoProvider.GetMediaFilePath(mfi.FileLibraryID, mfi.FilePath))) { // Get new dimensions int[] newDims = ImageHelper.EnsureImageDimensions(Width, Height, MaxSideSize, mfi.FileImageWidth, mfi.FileImageHeight); // If dimensions changed use secure link if ((newDims[0] != mfi.FileImageWidth) || (newDims[1] != mfi.FileImageHeight)) { if (completeUrl) { url = MediaFileInfoProvider.GetMediaFileAbsoluteUrl(si.SiteName, mfi.FileGUID, mfi.FileName); } else { url = MediaFileInfoProvider.GetMediaFileUrl(mfi.FileGUID, mfi.FileName); } } else { // Use width and height from properties in case dimensions are bigger than original newDims[0] = Width; newDims[1] = Height; } // Initialize image parameters ImageParameters imgParams = new ImageParameters(); imgParams.Alt = mfi.FileDescription; imgParams.Width = newDims[0]; imgParams.Height = newDims[1]; imgParams.Url = url; ltlOutput.Text = MediaHelper.GetImage(imgParams); } else if (MediaHelper.IsFlash(mfi.FileExtension)) { // Initialize flash parameters FlashParameters flashParams = new FlashParameters(); flashParams.Url = url; flashParams.Width = Width; flashParams.Height = Height; ltlOutput.Text = MediaHelper.GetFlash(flashParams); } else if (MediaHelper.IsAudio(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters audioParams = new AudioVideoParameters(); audioParams.SiteName = CMSContext.CurrentSiteName; audioParams.Url = url; audioParams.Width = Width; audioParams.Height = Height; audioParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(audioParams); } else if (MediaHelper.IsVideo(mfi.FileExtension)) { // Initialize audio/video parameters AudioVideoParameters videoParams = new AudioVideoParameters(); videoParams.SiteName = CMSContext.CurrentSiteName; videoParams.Url = url; videoParams.Width = Width; videoParams.Height = Height; videoParams.Extension = mfi.FileExtension; ltlOutput.Text = MediaHelper.GetAudioVideo(videoParams); } else { ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page, DefaultImageUrl); } } else { ltlOutput.Text = MediaLibraryHelper.ShowPreviewOrIcon(mfi, Width, Height, MaxSideSize, PreviewSuffix, IconSet, Page, DefaultImageUrl); } } } } binded = true; } }