The same is observed with the Thumbnail images in the RadImageGallery, which actually use such BinaryImages.
Note: The attached image should be the only file in a "Images" in the root of the application
protected void Page_Load(object sender, EventArgs e)
{
var binary = new RadBinaryImage();
binary.AutoAdjustImageControlSize = false;
binary.ResizeMode = BinaryImageResizeMode.Crop;
binary.ID = "BinaryImage";
binary.Width = Unit.Pixel(100);
binary.Height = Unit.Pixel(100);
var path = Directory.EnumerateFiles(Server.MapPath("~/Images")).First();
binary.DataValue = File.ReadAllBytes(path);
Form.Controls.Add(binary);
}
protected void Page_Load(object sender, EventArgs e)
{
var binary = new RadBinaryImage();
binary.ID = "BinaryImage1";
binary.ResizeMode = BinaryImageResizeMode.Crop;
binary.Width = Unit.Pixel(100);
binary.Height = Unit.Pixel(100);
var path = Directory.EnumerateFiles(Server.MapPath("~/Images")).First();
binary.DataValue = ImagePathToByteArray(path);
//binary.DataValue = File.ReadAllBytes(path);
Form.Controls.Add(binary);
}
public byte[] ImagePathToByteArray(string path)
{
System.Drawing.Image img = Bitmap.FromFile(path);
if (Array.IndexOf(img.PropertyIdList, 274) > -1)
{
var orientation = (int)img.GetPropertyItem(274).Value[0];
switch (orientation)
{
case 1:
// No rotation required.
break;
case 2:
img.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
img.RotateFlip(RotateFlipType.Rotate180FlipX);
break;
case 5:
img.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
img.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
// This EXIF data is now invalid and should be removed.
img.RemovePropertyItem(274);
}
return ImageToByte(img);
}
public static byte[] ImageToByte(System.Drawing.Image img)
{
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
All Server applications seeking Windows Server Logo fail the test when using Telerik based binaries. Please use best practices and adopt Authenticode signature and include file information in binaries for security as well as Customer identification of file owners.
System.Threading.ThreadAbortException 2 Thread was being aborted. System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) System.Exception 1 <none> System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) System.OutOfMemoryException 1 <none> System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) System.StackOverflowException 1 <none> System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) System.ExecutionEngineException 1 <none> System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef) System.Threading.ThreadAbortException 2 <none> System.Threading.Thread.AbortInternal() System.Threading.Thread.Abort(System.Object) System.Web.HttpResponse.AbortCurrentThread() Telerik.Web.UI.RadBinaryImageHandler.ProcessRequestInternal() Telerik.Web.UI.HandlerRouter.ProcessHandler(System.String, System.Web.HttpContext) Telerik.Web.UI.WebResource.ProcessRequest(System.Web.HttpContext) System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() System.Web.HttpApplication.ExecuteStep(IExecutionStep, Boolean ByRef)
I'd like to be able to instantiate and databind a RadBinaryImage, then call a "GetUri" method on the instance to get the WebResource URI that would be generated in markup if the control were added to the page. In a particular use case, this would allow putting the URI in a meta tag for OpenGraph calls. An additional API method that would be handy would be a "handler" mode that would allow instantiation of a RadBinaryImage in a custom IHttpHandler implementation, and then serving that request from the final image (after scaling and cropping) generated by the RadBinaryImage control. I could see this taking two forms: * GetMimeType and GetBytes methods, which could be used to manually populate the Response. * a Respond method which would take an HttpContext argument, and would set appropriate headers, stream the image, and end the request itself.