Click here to Skip to main content
15,887,329 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
VB
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

    Dim businessId As Integer = 0
    Dim strLogo As String = String.Empty
    Dim FileLogo As String = String.Empty
    Dim userId As Integer = 0
    userId = Convert.ToInt32(Session(Common.SESSION_USERID).ToString())

    If (flLogo.HasFile) Then
        Dim strPath As String = Server.MapPath("Common/WebSiteImages/")
        flLogo.SaveAs(strPath + flLogo.FileName)
        FileLogo = flLogo.FileName
        strLogo = "Common/WebSiteImages/" + flLogo.FileName
        Dim big As String = "~Big"
        big = resizeImageAndSave(strLogo, 450, 420, big)
        Dim thumb As String = "~Thumb"
        thumb = resizeImageAndSave(strLogo, 240, 172, thumb)
    Else
        strLogo = ViewState("Logo")
        If (strLogo Is Nothing) Then
            strLogo = String.Empty
        Else
            strLogo = ViewState("Logo")
        End If
    End If
    Dim dt As New DataTable()
    dt = GetWebsiteProfile(userId)
    If (dt Is Nothing) Then
        businessId = InsertUpdateBusinessSettings(0, userId, txtAddress.Text, txtPhoneNo.Text, editorDesc.Content, strLogo, txtCopyRight.Text,editorServices.Content)
        If businessId > 0 Then
            lblMsg.Text = "inserted successfuly...."
            lblMsg.ForeColor = System.Drawing.Color.Green
        End If
    Else
        Dim businessIdd As Integer = dt.Rows(0)("Id").ToString()
        If dt IsNot Nothing Then
            businessId = InsertUpdateBusinessSettings(businessIdd, userId, txtAddress.Text, txtPhoneNo.Text, editorDesc.Content, strLogo, txtCopyRight.Text,editorServices.Content)
            If businessId > 0 Then
                lblMsg.Text = "updated successfuly...."
                lblMsg.ForeColor = System.Drawing.Color.Green
            End If
        End If
    End If
End Sub




VB
Private Function resizeImageAndSave(ByVal imagePath As String, ByVal width As Integer, ByVal height As Integer, ByVal name As String) As String
        imagePath = "D:\Aman\FindURBiz\Abhi\250814findurbiz\findurbiz\FindurBiz\" & imagePath
        Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(imagePath)
        Dim thumbnailImg = New Bitmap(width, height)
        Dim thumbGraph = Graphics.FromImage(thumbnailImg)
        thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
        thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
        thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
        Dim imageRectangle = New Rectangle(0, 0, width, height)
        thumbGraph.DrawImage(fullSizeImg, imageRectangle)
        Dim withoutExtension As String = imagePath
        Dim strImage As String = String.Empty
        Dim strArr() As String
        strArr = withoutExtension.Split(".")
        strImage = strArr(0)
        imagePath = strImage + ".jpg"

        Dim targetPath As String = imagePath.Replace(Path.GetFileNameWithoutExtension(imagePath), Path.GetFileNameWithoutExtension(imagePath) & name)


        thumbnailImg.Save(targetPath, System.Drawing.Imaging.ImageFormat.Jpeg)

        thumbnailImg.Dispose()
        Dim bigimage As String = String.Empty
        Return targetPath
        ViewState("targetPath") = bigimage

    End Function


My Problem-: When a small image to converted a big image then this image resolution is not good.

Please help me its very urgent...........
Posted

1 solution

Do you mean that quality is not good? That is be be expected when trying to enlarge a low resolution image. You have to remember that an image such as a jpg is already compressed and made up of pixels or dots. When you enlarge an jpg you are adding pixels based on a best guess of neighboring pixels.

Your best bet is to start with high rez images.

/*Update----------------------------*/

As I mentioned above increasing the resolutions of a small image will only work up to a certain percentage. After that then you will get pixelation or distortion. This is just the nature of working with pixel based images.

There are some libraries that might help, but mileage will vary.

http://stackoverflow.com/questions/249587/high-quality-image-scaling-c-sharp[^]
 
Share this answer
 
v2
Comments
abhishek burnwal Kolkata 27-Aug-14 9:45am    
I want to make it image resolution high. How to make it?
AnvilRanger 27-Aug-14 10:13am    
View the updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900