Eric Wise

Sponsors

The Lounge

Wicked Cool Jobs

Blogs I Read

Fun & Games

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.


Posted Tue, May 10 2005 6:45 AM by Eric Wise

[Advertisement]

Comments

Eric Wise wrote Images, Thumbnails, SQL Server, and ASP .NET - Level 200
on Sun, May 15 2005 6:51 PM
Ok, it's been a bit of time since I posted some technical content.  I seem to be the only codebetter...
Vince wrote re: Here's a nifty free tool
on Fri, Aug 25 2006 2:55 PM

not free :(

Eric Wise wrote re: Here's a nifty free tool
on Fri, Aug 25 2006 10:04 PM

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

Ashraf wrote re: Here's a nifty free tool
on Sun, Jan 14 2007 1:20 AM

thanks alot for helping me ..

Ashraf Ibrahim wrote re: Here's a nifty free tool
on Sun, Jan 14 2007 2:43 AM

Thanxs...

Annas wrote re: Here's a nifty free tool
on Wed, Jan 2 2008 7:04 AM

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

DotNetKicks.com wrote my story
on Sat, Jun 21 2008 1:28 AM

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

mahdavi wrote re: Here's a nifty free tool
on Thu, Jul 24 2008 1:36 AM

How to convert large image into thumbnail using asp.net

Devlicio.us