CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

Here's a nifty free tool

http://www.paymon.net/Pages/Show.aspx?page=17

Image compression tool for those of you who want to allow users to upload large images without having to have the user go through the pain of compression.  In a test it chunked down a 1.2mb image I uploaded to a mere 50ish kb.  Image still looked good when displayed as well.  The tool was very easy to configure and use.

Look for an article this week from me about image upload, generating a thumbnail, store/retrieve image data from sql server in Easy Assets .NET.

Yeah, I suppose I should mention that I'm adding a feature to assets to allow pictures to be stored for insurance purposes.



Comments

Eric Wise said:

Ok, it's been a bit of time since I posted some technical content.  I seem to be the only codebetter...
# May 15, 2005 6:51 PM

Vince said:

not free :(

# August 25, 2006 2:55 PM

Eric Wise said:

Used to be, back when I posted it.  Now it's charged.

# August 25, 2006 10:04 PM

Ashraf said:

thanks alot for helping me ..

# January 14, 2007 1:20 AM

Ashraf Ibrahim said:

Thanxs...

# January 14, 2007 2:43 AM

Annas said:

hi,

my Q is :

Imports System.Data

Imports System.Data.SqlClient

Imports System.IO

Imports System.Drawing

Imports System.Drawing.Imaging

Public Class image

   Inherits System.Web.UI.Page

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       'Put user code to initialize the page here

       If Not Page.IsPostBack Then

           Dim assetImg As New EasyAssets.DAC.AssetImage(Convert.ToInt32(Request.QueryString("ID")))

           assetImg = DirectCast(DomainManager.Load(assetImg), EasyAssets.DAC.AssetImage)

           Response.ContentType = "Image/JPEG"

           Response.BinaryWrite(assetImg.Thumbnail)

       End If

   End Sub

   Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click

       Try

           Dim upfile As HttpPostedFile =UploadFile.PostedFile

           If upfile.ContentLength <> Nothing Then

               Dim myData() As Byte

               Dim stream As New MemoryStream

               Dim assetImage As New EasyAssets.DAC.AssetImage

               myData = ImageOptimizer1.Optimize(upfile)

               assetImage.FileSize = Convert.ToInt32(myData.Length / 1000)

               Dim i As Integer = InStrRev(upfile.FileName.Trim, "\")

               If i = 0 Then

                   assetImage.FileName = upfile.FileName.Trim

               Else

                   assetImage.FileName = Right(upfile.FileName.Trim, Len(upfile.FileName.Trim) - i)

               End If

               assetImage.AssetID = Convert.ToInt32(Request.QueryString("AID"))

               assetImage.FileData = myData

               assetImage.ContentType = upfile.ContentType

               Dim thumbnail As Bitmap = CreateThumbNail(New Bitmap(upfile.InputStream, False), 120, 120)

               thumbnail.Save(stream, ImageFormat.Jpeg)

               assetImage.Thumbnail = stream.GetBuffer()

               DomainManager.Save(assetImage)

               BindDataGrid()

           End If

       Catch ex As Exception

           WriteMessage(ex.Message, True)

       End Try

   End Sub

   Private Function CreateThumbNail(ByVal postedFile As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap

       Dim bmpOut As System.Drawing.Bitmap

       Dim Format As ImageFormat = postedFile.RawFormat

       Dim Ratio As Decimal

       Dim NewWidth As Integer

       Dim NewHeight As Integer

       '*** If the image is smaller than a thumbnail just return it        

       If postedFile.Width < width AndAlso postedFile.Height < height Then

           Return postedFile

       End If

       If (postedFile.Width > postedFile.Height) Then

           Ratio = Convert.ToDecimal(width / postedFile.Width)

           NewWidth = width

           Dim Temp As Decimal = postedFile.Height * Ratio

           NewHeight = Convert.ToInt32(Temp)

       Else

           Ratio = Convert.ToDecimal(height / postedFile.Height)

           NewHeight = height

           Dim Temp As Decimal = postedFile.Width * Ratio

           NewWidth = Convert.ToInt32(Temp)

       End If

       bmpOut = New Bitmap(NewWidth, NewHeight)

       Dim g As Graphics = Graphics.FromImage(bmpOut)

       g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

       g.FillRectangle(Brushes.White, 0, 0, NewWidth, NewHeight)

       g.DrawImage(postedFile, 0, 0, NewWidth, NewHeight)

       postedFile.Dispose()

       Return bmpOut

   End Function

   Protected Function FormatURL(ByVal imageID As Integer) As String

       Return ("AssetShowThumb.aspx?id=" & imageID.ToString())

   End Function

   Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged

   End Sub

End Class

-------------------------------------------------------------------------------------

Err : using namespace also

EasyAssets.DAC.AssetImage   is not defined

other are not declared

# January 2, 2008 7:04 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 21, 2008 1:28 AM

mahdavi said:

How to convert large image into thumbnail using asp.net

# July 24, 2008 1:36 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors