I have a RadBinaryImage control and I want to implement a custom httphandeler but I am having a bit of trouble doing this task. The reason for my custom implementation is that I have images stored in my DB as binary that are 100kb in size I have a page which displays up to 170 of these images as thumbnail size but the are still 100kb in size. So at times when the page is rendered some images will not show.
I tried using the AutoAdjustImageControlSize and ResizeMode and had not acheived the desired effect. I may be going about this the hard way but i wrote a handler to reduce and resize the images and spit the binary out but I can't seem to get it to work. This is my handeler
and this is my ImageThumbnailer class
I f i am going about this the wrong way please let me know. I want the thumb nails to be less bytes when it is rendered to the page which will increase the speed and resolve the issue of images not being rendered. The page in question is at the current url @ http://www.4dpeeps.com
I tried using the AutoAdjustImageControlSize and ResizeMode and had not acheived the desired effect. I may be going about this the hard way but i wrote a handler to reduce and resize the images and spit the binary out but I can't seem to get it to work. This is my handeler
Public Class RenderImageHandler Implements System.Web.IHttpHandler Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim Response As HttpResponse = context.Response ' Dim ImageUrl As bi = HttpContext.Current.Server.MapPath("~/01SC087.JPG") Dim imgLoader As New PService Dim id As Integer Integer.TryParse(context.Request.QueryString("i_id"), id) If id > 0 Then Dim ic As New ImageConverter() Dim imgN As Image = DirectCast(ic.ConvertFrom(imgLoader._GetPostingImg(id)), Image) Dim bitmap1 As New Bitmap(imgN) Dim thumbnailer As New ImageThumbnailer() Dim bmp As System.Drawing.Bitmap = thumbnailer.CreateThumbnail(bitmap1, 150, 150, True) Dim ms As New System.IO.MemoryStream() bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp) Dim imageData As Byte() = ms.GetBuffer() Response.ContentType = "image/jpeg" context.Response.BinaryWrite(imageData) context.Response.Flush() End If End Sub ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Classand this is my ImageThumbnailer class
Public Class ImageThumbnailer Private _thumb As Bitmap = Nothing Public Function CreateThumbnail(ByVal SourceImage As Bitmap, ByVal Width As Int32, ByVal Height As Int32, ByVal KeepRatio As [Boolean]) As Bitmap ' if Source Bitmap smaller than designated thumbnail => Return Original If SourceImage.Width < Width AndAlso SourceImage.Height < Height Then Return SourceImage End If Try Dim _Width As Int32 = 0 Dim _Height As Int32 = 0 _Width = Width _Height = Height If KeepRatio Then If SourceImage.Width > SourceImage.Height Then _Width = Width _Height = CType(SourceImage.Height * (Width / SourceImage.Width), Int32) Else _Height = Height _Width = CType(SourceImage.Width * (Height / SourceImage.Height), Int32) End If End If _thumb = New Bitmap(_Width, _Height) Using g As Graphics = Graphics.FromImage(_thumb) g.InterpolationMode = InterpolationMode.HighQualityBicubic g.FillRectangle(Brushes.White, 0, 0, _Width, _Height) g.DrawImage(SourceImage, 0, 0, _Width, _Height) End Using Catch _thumb = Nothing End Try Return _thumb End Function End ClassI f i am going about this the wrong way please let me know. I want the thumb nails to be less bytes when it is rendered to the page which will increase the speed and resolve the issue of images not being rendered. The page in question is at the current url @ http://www.4dpeeps.com