locked
Userid to show images RRS feed

  • Question

  • User1982870178 posted

    Hello ~ I’m looking for some advice to help me get started on a image gallery I need to add to my site.  I’ve looked at several and have found some that would fit my needs. I only need something simple that shows thumbnails and will plug into the asp enviourment. The ones I found also uses Jquery or Flash. I am not PHP savvy, so that’s out for me. My problem is; My site will allow people to sell their product. I have two tables, one for the product information and one for their photo’s.  The photo’s table also is saved in a file, one for image and one for thumbnails, which I can tweak the size of. What I want to do is have a customer click on a picture, in the brief description of the product  and be able to view all the picture’s of that product.  What I’m having a problem with is how to link the images to the userid so only those images are viewed in the gallery. The number of images for the product my be one or thirty one. I’m not getting how to do this. What I’ve explored is css and script like this IGImage addImage = IGImageLocalServiceUtil.addImage(userId, folderId, imageName, description, file, contentType, new ServiceContext()); I’m lost! From my understanding this want’s you to manually imput info. I want to understand what I’m doing not just copy and past. So any direction you folks can give me so I can get started would be greatly appreciated. Oh I don’t know if this would help me but the gallery I’m looking at is at

    http://smoothgallery.jondesign.net/ it’s a open source gallery. It’ simple, fits my needs and has all the right stuff for me to wire into my asp site. If you have any suggestions other wise I will for sure check them out. The big thing is how you link userid, images to the image gallery, so it only shows the images for their product. I’m sure I’ve made this just as clear as MUD…Please suggest to get me started.

    Thanks

    Thursday, October 11, 2012 7:39 PM

All replies

  • User3866881 posted

    Hello,

    So would you mind telling me your design of your table schema?And where to save the image?where to fetch the image out and bind to the GridView or some data presentation control?

    Reguards!

    Saturday, October 13, 2012 8:54 PM
  • User1982870178 posted

    Thanks for the response Decker Dong

    Hope this is information is what you are looking for. My table schema is as follows; The first table collects company name, email, phone numbers, product description, et. The second is the image table, the user clicks on the down load images link and the program is as follows.

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System.Configuration

    Imports System.IO

    Imports System.Drawing

    Imports System

    Imports System.Collections.Generic

    Imports System.Web

    Imports System.Web.UI

    Imports System.Web.UI.WebControls

    Imports System.Collections

    Imports System.Web.Security

    Imports System.Web.UI.HtmlControls

    Partial Class HomePics

        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim dvSql As DataView = DirectCast(UploadNewImageSqlDataSource.[Select](DataSourceSelectArguments.Empty), DataView)

           lblNewDate.Text = DateTime.Now.ToString()

        End Sub

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

            Const bmpW As Integer = 300 'New image canvas width

            Const bmpH As Integer = 225 'New Image canvas height

            'ratio is width * 0.75 = Height

            If (FileUpload1.HasFile) Then

               lblError.Text = ""

                If (CheckFileType(FileUpload1.FileName)) Then

                   Dim newWidth As Integer = bmpW

                   Dim newHeight As Integer = bmpH

                   Dim fileName As String = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName)

                   Dim timeStampedPath As String = (fileName & "-") + DateTime.Now.Ticks.ToString()

                   Dim thefilePath As String = "~\uploaded_images\" & timeStampedPath & ".png"

                   lblImage.Text = thefilePath

                   Dim thumbnailfilePath As String = "~\Thumbnail_uploaded_images\" & timeStampedPath & ".png"

                   lblImageThumbnail.Text = thumbnailfilePath

                   Dim upBmp As Bitmap = Bitmap.FromStream(FileUpload1.PostedFile.InputStream)

                   Dim newBmp As Bitmap = New Bitmap(newWidth, newHeight, Imaging.PixelFormat.Format24bppRgb)

                   newBmp.SetResolution(72, 72)

                   Dim upWidth As Integer = upBmp.Width

                   Dim upHeight As Integer = upBmp.Height

                   Dim newX As Integer = 0

                   Dim newY As Integer = 0

                   Dim reDuce As Decimal

                   If upWidth > upHeight Then 'Landscape picture

                       reDuce = newWidth / upWidth

                       newHeight = Int(upHeight * reDuce)

                       newY = Int((bmpH - newHeight) / 2)

                       newX = 0

                   ElseIf upWidth < upHeight Then 'Portrait picture

                       reDuce = newHeight / upHeight

                       newWidth = Int(upWidth * reDuce)

                       newX = Int((bmpW - newWidth) / 2)

                       newY = 0

                   ElseIf upWidth = upHeight Then 'square picture

                       reDuce = newHeight / upHeight

                       newWidth = Int(upWidth * reDuce)

                       newX = Int((bmpW - newWidth) / 2)

                       newY = Int((bmpH - newHeight) / 2)

                   End If

                   Dim newGraphic As Graphics = Graphics.FromImage(newBmp)

                   Try

                       newGraphic.Clear(Color.White)

                       newGraphic.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

                       newGraphic.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic

                       newGraphic.DrawImage(upBmp, newX, newY, newWidth, newHeight)

                       newBmp.Save(MapPath(thefilePath), Imaging.ImageFormat.Png)

                       Image1.ImageUrl = thefilePath

                       Image1.Visible = True

                   Catch ex As Exception

                       lblError.Text = "ERROR: " & ex.ToString

                   Finally

                       upBmp.Dispose()

                       newBmp.Dispose()

                       newGraphic.Dispose()

                   End Try

                Else

                   lblError.Text = "Please select a picture with a file format extension of either Bmp, Jpg, Jpeg, Gif or Png."

                End If

            End If

            Dim newThumbnailImagepath As String = lblImageThumbnail.Text

            Dim justNewCompanyImagepath As String = lblImage.Text

            Dim justnewImagepath As String = Server.MapPath(justNewCompanyImagepath)

            Dim ThumbnailPath As String = Server.MapPath(newThumbnailImagepath)

            Dim Img As System.Drawing.Image = System.Drawing.Image.FromFile(justnewImagepath)

            Dim ThumbNailSize As Size = NewImageSize(Img.Height, Img.Width)

            Dim ImgThnail As System.Drawing.Image = New Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height)

           ImgThnail.Save(ThumbnailPath, Img.RawFormat)

            Dim ImagesDataSource As New SqlDataSource()

            Dim myObject As MembershipUser = Membership.GetUser()

            Dim UserID As String = myObject.ProviderUserKey.ToString()

           ''UploadNewImageSqlDataSource is to upload new images into database

           UploadNewImageSqlDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ImagesConnectionString1").ToString()

           UploadNewImageSqlDataSource.InsertCommandType = SqlDataSourceCommandType.Text

           UploadNewImageSqlDataSource.InsertCommand = "INSERT INTO [CompanyDetails] ([UserId], [CompanyImage],[CompanyThumbnail]) VALUES (@UserId, @CompanyImage,@CompanyThumbnail)"

           UploadNewImageSqlDataSource.InsertParameters(0).DefaultValue = UserID

           UploadNewImageSqlDataSource.InsertParameters(1).DefaultValue = lblImage.Text

           UploadNewImageSqlDataSource.InsertParameters(2).DefaultValue = lblImageThumbnail.Text

           'UploadNewImageSqlDataSource.InsertParameters(3).DefaultValue = DateTime.Now.ToString()

           UploadNewImageSqlDataSource.Insert()

        End Sub

        Private Function NewImageSize(ByVal OriginalHeight As Integer, ByVal OriginalWidth As Integer) As Size

            Dim NewSize As Size

            Dim tempval As Double

            If OriginalHeight > 75 AndAlso OriginalWidth > 75 Then

                If OriginalHeight > OriginalWidth Then

                   tempval = 75.0R / Convert.ToDouble(OriginalHeight)

                Else

                   tempval = 75.0R / Convert.ToDouble(OriginalWidth)

                End If

               NewSize = New Size(Convert.ToInt32(tempval * OriginalWidth), Convert.ToInt32(tempval * OriginalHeight))

            Else

               NewSize = New Size(OriginalWidth, OriginalHeight)

            End If

            Return NewSize

        End Function

        Function CheckFileType(ByVal fileName As String) As Boolean

            Dim ext As String = Path.GetExtension(fileName)

            Select Case ext.ToLower()

                Case ".gif"

                   Return True

                Case ".png"

                   Return True

                Case ".jpg"

                   Return True

                Case ".jpeg"

                   Return True

                Case ".bmp"

                   Return True

                Case Else

                   Return False

            End Select

        End Function

    End Class

    This resizes the image and creates a thumbnail, My sql database then saves the path to the files. As such under userid and CompanyId;

    CompanyID int

    UserId     uniqueidentifier

    CompanyImage   nvarchar (300)

    CompanyThmnail   nvarchar (300)

    timestamp   timestamp

    This takes the image and resizes it, creates a thumbnail and stores the path for them database.

    My files are Thumbnailimages and file: loadedimages

    I've not been using gridview at this point. But this is where my problem is, maybe I should be? How do I take this information and link it to a image gallery? I only want the pictures displayed for the customer clicking on the product picture. So in other words they see a brief description of the product, click on the picture and all the images of that product come up in the image gallery. I know how to link the picture to the database or files, but that's where my knowledge ends. I could post my many failed  attempts, but why. LOL. Here is some of my latest programing I'm been trying to wire up. Maybe I need to create a directory for each customer?  Save there information in there, then link to it? Hey as you can see I'm lost. Just want some good advise so I can carry on my quest. 


     

    Imports System 
    Imports System.IO 
     Public Class Test 
     Public Shared Sub Main() 
     ' Specify the directories you want to manipulate. 
     Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir") 
     Try 
     ' Determine whether the directory exists. 
     If di.Exists Then 
     ' Indicate that it already exists. 
     Console.WriteLine("That path exists already.") 
     Return 
     End If 
     ' Try to create the directory. 
     di.Create() 
     Console.WriteLine("The directory was created successfully.") 
     ' Delete the directory. 
     di.Delete() 
     Console.WriteLine("The directory was deleted successfully.") 
     Catch e As Exception 
     Console.WriteLine("The process failed: {0}", e.ToString()) 
     End Try 
     End Sub 
    End Class 

    Sorry for the long response but it's the only way I can explain. Hope this was the information you were looking for. If not just let me know and will try and supply you  with what more I have so far. Hey thanks Decker Dong and to all you folks that help us...  Really, it means a lot to me. I don't ask for help often, but when I have you folks have been there. Great Forum...

    Thank You :)

    Sunday, October 14, 2012 2:17 AM