I have VB.NET code that puts the user's latest 4 uploaded photos onto a gray background banner (576x111).
It works but the 4 photos (each 144x111) photos appear smaller on the banner than they are.
Here's how they appear:
Here's how I want them to appear:
Here's the code that places them onto the gray background image:
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class TFsfPhotoBanner
#Region "Dims"
Dim cGeneral As New sfGeneral
Dim strClsProfileOwnerEmailAddress As String
Dim strClsProfileViewerEmailAddress As String
#End Region
#Region "Functions"
''' <summary>
''' Returns image strip of latest uploaded photos for profile owner.
''' </summary>
''' <param name="strProfileOwnerEmailAddress"></param>
''' <param name="strProfileViewerEmailAddress"></param>
''' <param name="imgGetBackground"></param>
''' <returns></returns>
''' <remarks></remarks>
Function fProfileBannerGet( _
ByVal strProfileOwnerEmailAddress As String, _
ByVal strProfileViewerEmailAddress As String, _
ByRef imgGetBackground As System.Drawing.Image) _
As Boolean
'Dim lngDPIX As Long = 216
'Dim lngDPIY As Long = 222
strClsProfileOwnerEmailAddress = strProfileOwnerEmailAddress
strClsProfileViewerEmailAddress = strProfileViewerEmailAddress
'Get panel background
Dim strBackgroundFilePath As String = HttpContext.Current.Server.MapPath("~/pages/profile/view/photo_banner/images/profile_panel_background.png")
Dim imgFrameBackground As Bitmap = DirectCast(Image.FromFile(strBackgroundFilePath), Bitmap)
'imgFrameBackground.SetResolution(lngDPIX, lngDPIY)
Dim g As Graphics = Graphics.FromImage(imgFrameBackground)
g.SmoothingMode = SmoothingMode.HighQuality
g.TextRenderingHint = Text.TextRenderingHint.ClearTypeGridFit
'Add thumbnails
Dim bolImageReturn As Boolean
Dim strListURLs As List(Of String) = Nothing
Dim intXPosition As Integer
bolImageReturn = fGetLatestImagesURLs(strListURLs)
Dim strLocalSuffix As String = ""
Dim strLocalFilePath As String = ""
For Each strImageURL As String In strListURLs
strLocalSuffix = "~" + Mid(strImageURL, strImageURL.IndexOf("/pages/") + 1)
strLocalFilePath = HttpContext.Current.Server.MapPath(strLocalSuffix)
g.DrawImage(Image.FromFile(strLocalFilePath), New Point(intXPosition, 1))
intXPosition += 144
Next
imgGetBackground = imgFrameBackground
g.Dispose()
End Function
''' <summary>
''' Get top 4 latest images.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function fGetLatestImagesURLs(ByRef imgListReturned As List(Of String)) As Boolean
Dim sqlConnection1 As New SqlConnection(cGeneral.fGetConnectionString)
Dim cmd As New SqlCommand
Dim dr As SqlDataReader = Nothing
Dim strReturn As String
Dim c As TFsfMemberImages
Dim lngCounterID As Long
Dim imgList As New List(Of String)
cmd.Connection = sqlConnection1
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "uspTSTFMemberImageProfilePanelImagesGet"
cmd.Parameters.AddWithValue("@EnterObjectOwnerEmailAddress", strClsProfileOwnerEmailAddress)
cmd.Parameters.AddWithValue("@EnterObjectViewerEmailAddress", strClsProfileViewerEmailAddress)
Try
sqlConnection1.Open()
dr = cmd.ExecuteReader
While dr.Read()
lngCounterID = dr("CounterID")
c = New TFsfMemberImages(lngCounterID)
imgList.Add(c.pImageURL)
End While
Catch ex As SqlException
strReturn = ex.ToString
Return strReturn
Finally
sqlConnection1.Close()
sqlConnection1.Dispose()
cmd.Dispose()
If dr IsNot Nothing Then
dr.Close()
End If
End Try
imgListReturned = imgList
End Function
#End Region
End Class
You'll notice that I have commented-out the following lines:
'Dim lngDPIX As Long = 216
'Dim lngDPIY As Long = 222
'imgFrameBackground.SetResolution(lngDPIX, lngDPIY)
The reason is that I did a right-click properties on each of the 4 sample images in windows photo viewer and found they had a setting "Horizontal DPI: 216 and Vertical DPI: 222"
This made me experiment with the 3 lines of code above and I found that if I uncommented them then the pictures all appeared perfectly on the 576x111 gray background image as shown in the second sample image above.
That's fine but they are sample images. The users will have all sort of uploaded photos though I do use the following code to create a 144x111 thumnail of each of them when they upload the image:
imgThumbNail = imgOrginal.GetThumbnailImage(lngWidth, lngHeight, Nothing, New IntPtr())
So my question is, how can I make it so that I can put these 144x111 thumbnails on the gray background without their being unusal sizes depending on each photo's X and Y DPI?
You can hardcode the width and height of the image in your aspx page or use imagebutton and display them in it. In both you can control the size of the image. But when user upload happens, you will get images of various sizes and may get distorted.
Please mark as answered if this answer helped you.
Oh -- perhaps I should have explained better, there is only one image, it's dynamically generated as a mosaic as follows:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.IO
Partial Class pages_photo_banner
Inherits System.Web.UI.Page
Dim cGeneral As New sfGeneral
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strViewerEmailAddress As String = Session("TFMyLoginEmailAddress")
Dim strOwnerEmailAddress As String = fGetOwnerEmailAddress()
Response.ContentType = "image/png"
Response.BufferOutput = True
Dim c2 As New TFsfPhotoBanner
Dim imgGetBackground As System.Drawing.Image = Nothing
Dim bolResult As Boolean
bolResult = c2.fProfileBannerGet( _
strOwnerEmailAddress, _
strViewerEmailAddress, _
imgGetBackground)
Dim bmp As Bitmap = imgGetBackground
Dim ms As MemoryStream = New MemoryStream()
bmp.Save(ms, ImageFormat.Png)
ms.WriteTo(Response.OutputStream)
bmp.Dispose()
Response.Flush()
End Sub
Mark Br
Member
89 Points
173 Posts
Why are these images appearing too small on my images banner?
Mar 24, 2012 04:06 AM|LINK
Hi
I have VB.NET code that puts the user's latest 4 uploaded photos onto a gray background banner (576x111).
It works but the 4 photos (each 144x111) photos appear smaller on the banner than they are.
Here's how they appear:
Here's how I want them to appear:
Here's the code that places them onto the gray background image:
Imports Microsoft.VisualBasic Imports System.Data.SqlClient Imports System.Data Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Drawing2D Imports System.IO Public Class TFsfPhotoBanner #Region "Dims" Dim cGeneral As New sfGeneral Dim strClsProfileOwnerEmailAddress As String Dim strClsProfileViewerEmailAddress As String #End Region #Region "Functions" ''' <summary> ''' Returns image strip of latest uploaded photos for profile owner. ''' </summary> ''' <param name="strProfileOwnerEmailAddress"></param> ''' <param name="strProfileViewerEmailAddress"></param> ''' <param name="imgGetBackground"></param> ''' <returns></returns> ''' <remarks></remarks> Function fProfileBannerGet( _ ByVal strProfileOwnerEmailAddress As String, _ ByVal strProfileViewerEmailAddress As String, _ ByRef imgGetBackground As System.Drawing.Image) _ As Boolean 'Dim lngDPIX As Long = 216 'Dim lngDPIY As Long = 222 strClsProfileOwnerEmailAddress = strProfileOwnerEmailAddress strClsProfileViewerEmailAddress = strProfileViewerEmailAddress 'Get panel background Dim strBackgroundFilePath As String = HttpContext.Current.Server.MapPath("~/pages/profile/view/photo_banner/images/profile_panel_background.png") Dim imgFrameBackground As Bitmap = DirectCast(Image.FromFile(strBackgroundFilePath), Bitmap) 'imgFrameBackground.SetResolution(lngDPIX, lngDPIY) Dim g As Graphics = Graphics.FromImage(imgFrameBackground) g.SmoothingMode = SmoothingMode.HighQuality g.TextRenderingHint = Text.TextRenderingHint.ClearTypeGridFit 'Add thumbnails Dim bolImageReturn As Boolean Dim strListURLs As List(Of String) = Nothing Dim intXPosition As Integer bolImageReturn = fGetLatestImagesURLs(strListURLs) Dim strLocalSuffix As String = "" Dim strLocalFilePath As String = "" For Each strImageURL As String In strListURLs strLocalSuffix = "~" + Mid(strImageURL, strImageURL.IndexOf("/pages/") + 1) strLocalFilePath = HttpContext.Current.Server.MapPath(strLocalSuffix) g.DrawImage(Image.FromFile(strLocalFilePath), New Point(intXPosition, 1)) intXPosition += 144 Next imgGetBackground = imgFrameBackground g.Dispose() End Function ''' <summary> ''' Get top 4 latest images. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Private Function fGetLatestImagesURLs(ByRef imgListReturned As List(Of String)) As Boolean Dim sqlConnection1 As New SqlConnection(cGeneral.fGetConnectionString) Dim cmd As New SqlCommand Dim dr As SqlDataReader = Nothing Dim strReturn As String Dim c As TFsfMemberImages Dim lngCounterID As Long Dim imgList As New List(Of String) cmd.Connection = sqlConnection1 cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "uspTSTFMemberImageProfilePanelImagesGet" cmd.Parameters.AddWithValue("@EnterObjectOwnerEmailAddress", strClsProfileOwnerEmailAddress) cmd.Parameters.AddWithValue("@EnterObjectViewerEmailAddress", strClsProfileViewerEmailAddress) Try sqlConnection1.Open() dr = cmd.ExecuteReader While dr.Read() lngCounterID = dr("CounterID") c = New TFsfMemberImages(lngCounterID) imgList.Add(c.pImageURL) End While Catch ex As SqlException strReturn = ex.ToString Return strReturn Finally sqlConnection1.Close() sqlConnection1.Dispose() cmd.Dispose() If dr IsNot Nothing Then dr.Close() End If End Try imgListReturned = imgList End Function #End Region End ClassYou'll notice that I have commented-out the following lines:
The reason is that I did a right-click properties on each of the 4 sample images in windows photo viewer and found they had a setting "Horizontal DPI: 216 and Vertical DPI: 222"
This made me experiment with the 3 lines of code above and I found that if I uncommented them then the pictures all appeared perfectly on the 576x111 gray background image as shown in the second sample image above.
That's fine but they are sample images. The users will have all sort of uploaded photos though I do use the following code to create a 144x111 thumnail of each of them when they upload the image:
So my question is, how can I make it so that I can put these 144x111 thumbnails on the gray background without their being unusal sizes depending on each photo's X and Y DPI?
Shankar_ss
Participant
1270 Points
279 Posts
Re: Why are these images appearing too small on my images banner?
Mar 24, 2012 08:10 AM|LINK
You can hardcode the width and height of the image in your aspx page or use imagebutton and display them in it. In both you can control the size of the image. But when user upload happens, you will get images of various sizes and may get distorted.
Shankar
Mark Br
Member
89 Points
173 Posts
Re: Why are these images appearing too small on my images banner?
Mar 24, 2012 08:35 AM|LINK
Oh -- perhaps I should have explained better, there is only one image, it's dynamically generated as a mosaic as follows:
Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Drawing2D Imports System.IO Partial Class pages_photo_banner Inherits System.Web.UI.Page Dim cGeneral As New sfGeneral Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strViewerEmailAddress As String = Session("TFMyLoginEmailAddress") Dim strOwnerEmailAddress As String = fGetOwnerEmailAddress() Response.ContentType = "image/png" Response.BufferOutput = True Dim c2 As New TFsfPhotoBanner Dim imgGetBackground As System.Drawing.Image = Nothing Dim bolResult As Boolean bolResult = c2.fProfileBannerGet( _ strOwnerEmailAddress, _ strViewerEmailAddress, _ imgGetBackground) Dim bmp As Bitmap = imgGetBackground Dim ms As MemoryStream = New MemoryStream() bmp.Save(ms, ImageFormat.Png) ms.WriteTo(Response.OutputStream) bmp.Dispose() Response.Flush() End SubMark Br
Member
89 Points
173 Posts
Re: Why are these images appearing too small on my images banner?
Mar 27, 2012 03:27 AM|LINK
Can anyone else shed some light on this?
Mark Br
Member
89 Points
173 Posts
Re: Why are these images appearing too small on my images banner?
Mar 29, 2012 03:47 AM|LINK
My collegue gave me the following solution:
Use the overload g.DrawImage(img,x,y,width,height)