hi
is there is a way that image(of any size) can be shown properly(no distortions) according to table column size?
VB.NET 2005
Thanx
hi
is there is a way that image(of any size) can be shown properly(no distortions) according to table column size?
VB.NET 2005
Thanx
Last edited by richyrich; December 11th, 2008 at 10:52 AM.
Is this link any good for you?
Clicky
thanx RR, let me have a look![]()
ok i tried code from RR's link, i made this function
and calling it likeCode:Public Shared Function CreateThumbnail(ByVal lcFilename As String, ByVal lnWidth As Integer, ByVal lnHeight As Integer) As Bitmap 'http://www.west-wind.com/Weblog/posts/283.aspx Dim bmpOut As System.Drawing.Bitmap Try Dim loBMP As New Bitmap(lcFilename) Dim loFormat As ImageFormat = loBMP.RawFormat Dim lnRatio, lnTemp As Decimal Dim lnNewWidth As Integer = 0 Dim lnNewHeight As Integer = 0 'If image is smaller than a thumbnail, return it as such If loBMP.Width < lnWidth And loBMP.Height < lnHeight Then Return loBMP End If If loBMP.Width > loBMP.Height Then lnRatio = lnWidth / loBMP.Width lnNewWidth = lnWidth lnTemp = loBMP.Height * lnRatio lnNewHeight = CInt(lnTemp) Else lnRatio = lnHeight / loBMP.Height lnNewHeight = lnHeight lnTemp = loBMP.Width * lnRatio lnNewWidth = CInt(lnTemp) End If bmpOut = New Bitmap(lnNewWidth, lnNewHeight) Dim g As Graphics = Graphics.FromImage(bmpOut) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight) g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight) loBMP.Dispose() Catch ex As Exception 'Return False End Try Return bmpOut End Function
where strImage is a url coming from database.Code:Dim bmp As Bitmap = CreateThumbnail(strImage, 150, 150)
but now how do i show this image?
i am using an .net image control.
any ideas/suggestions??
What does he do with it in the example?
Could you save the bitmap as a file and then use the filename as the imageurl of an image control?
in the example, he saves it as a file, which i dont want.
but he also streams it to the browser like (C# code)
but i dont know how it works!!Code:Response.ContentType = "image/jpeg"; bmp.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
also i cant set bitmap as null
i used it like this
but it gives me this error at red lineCode:Dim bmp As Bitmap = CGlobal.CreateThumbnail(strImage, 150, 150) Response.ContentType = "image/jpeg" bmp.Save(Response.OutputStream, ImageFormat.Jpeg) bmp.Dispose()
Code:System.NullReferenceException: Object reference not set to an instance of an object.
I think the first parameter of the Save method should be the filename as a String
My guess is that your CreateThumbnail function is returning an error so the variable bmp never gets a value. Hence why you're getting the object reference error.
I noticed you don't have code in the Catch section of the Try in your function. Try something in there to see if an error occurs, catch it and write it to the screen.
hmm, i get this error
at this lineCode:System.ArgumentException: URI formats are not supported. at System.IO.Path.NormalizePathFast(String path, Boolean fullCheck) at System.IO.Path.GetFullPathInternal(String path) at System.IO.Path.GetFullPath(String path) at System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName) at System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
Code:Dim loBMP As New Bitmap(strImage)
Bookmarks