dev-exchange.com logo

dev-exchange.com latest topics RSS feed

Book mark: Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your delicious account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your digg account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your blinklist account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your reddit account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to Dzone Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your furl account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your stumble account Add http://www.dev-exchange.com/cms_view_article.php?aid=32&start=0&sid=38d2208ee43787acfeee1bb7fa575899 to your Yahoo myweb account
Article Menu
Google
ColdFusion MX
PHP
ASP
ASP.Net
XML-XSLT
JavaScript
SQL Server
AJAX
 


 
Article
net guru
Contributing Member
Contributing Member

Articles: 4 Comments: 2
 Posted: Tue Jul 01, 2008 10:57 am

This is one of the answers I posted on dev-exchange about a question about how to resize the images in asp.net. This example shows how to resize an image into thumbnail and full image using createthumb_fullimages function.

Add this function to your code behind

Code:

Function createthumb_fullimages(ByVal sOriginalImg As String, _
                                    ByVal sThumbImgFolder As String, _
                                    Optional ByVal sFullImgFolder As String = "") As Boolean

        Try
            'delegate to produce a dummy call back
            Dim fakeCallBack As System.Drawing.Image.GetThumbnailImageAbort
            fakeCallBack = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf FakeMethod)

            ' Original file name
            Dim sOrigFileName As String = System.IO.Path.GetFileName(sOriginalImg)

            Dim oImg As System.Drawing.Image
            oImg = System.Drawing.Image.FromFile(sOriginalImg)
            oImg = oImg.GetThumbnailImage(80, 80, fakeCallBack, IntPtr.Zero)
            oImg.Save(sThumbImgFolder + sOrigFileName, oImg.RawFormat)

            ' if full image is passed
            If Trim(sFullImgFolder) <> "" Then
                oImg = oImg.GetThumbnailImage(150, 150, fakeCallBack, IntPtr.Zero)
                oImg.Save(sFullImgFolder + sOrigFileName, oImg.RawFormat)
            End If

            Return True
        Catch ex As Exception
            ' some error occured. add message here
            Return False
        End Try
    End Function

    Function FakeMethod() As Boolean
        Return False
    End Function


Then call this on your upload button. Make sure that you are passing full path to image
and also you are giving the image directory path.


Code:

Protected Sub Uploaded_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

        ' Create Thumb nail and full image from the uploaded image
        If (createthumb_fullimages(Server.MapPath("~") + "/someuploaded.jpg", _
                                   Server.MapPath("~") + "/thumimgs/", _
                                   Server.MapPath("~") + "/fullimgs/") = True) Then

            Response.Write("Images created OK")
        Else
            Response.Write("Error Couldnt create Images")
        End If

    End Sub


This may help someone out there.
Rating: 0.00/5.00 [0]

Comments
No comments were made for this article
 

All times are GMT

Jump to:  
You cannot post articles in this chapter
You cannot edit your articles in this chapter
You cannot delete your articles in this chapter
You cannot rate articles in this chapter

You cannot post comments in this chapter
You cannot edit your comments in this chapter
You cannot delete your comments in this chapter
You cannot rate comments in this chapter


© 2008 dev-exchange.com
Powered by phpBB. Theme DEVPPL.