I am having problems with the "Content type" part of this. I dont have that field in my DB table and dont want to limit the user to only being able to upload .jpg for example.
How can we let the user upload any image type and then display them in this way?
ID - autonumber
adtext - text
imagename - text
imagevalue - OLE Object
I have sorted the image upload and it works well. I now need to get the image from the table and display it in a image controller (not gridview or anything)
For anyone needing to do what I needed here is what I did
I needed to limit the image size by that i mean limit the max heigh and max width (resize) and display here is the code that works fine for me, there is probably a simpler way but this works
'This is for resizing the image
Dim MaxHeight As Integer = 200
Dim MaxWidth As Integer = 800
Dim newImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("images/" & YourImageFileName))
Dim originalH As Integer = newImage.Height
Dim originalW As Integer = newImage.Width
If originalH > MaxHeight Then
'Need to resize
Dim HDiff As Integer = originalH - MaxHeight
Dim PerChange = 1 - (HDiff / originalH)
'Now we need to check if the new width is still bigger than max
Dim newWidth = originalW * PerChange
If newWidth > MaxWidth Then
'now we need to resize again
Dim Wdiff = newWidth - MaxWidth
Dim WPerChange = 1 - Wdiff / MaxWidth
Me.imgQ.Height = MaxHeight * WPerChange
Me.imgQ.Width = MaxWidth
Else
Me.imgQ.Height = MaxHeight
Me.imgQ.Width = originalW * PerChange
End If
ElseIf originalW > MaxWidth Then
'now we need to resize again
Dim Wdiff = originalW - MaxWidth
Dim WPerChange = 1 - Wdiff / MaxWidth
Me.imgQ.Height = MaxHeight * WPerChange
Me.imgQ.Width = MaxWidth
Else
'otherwise we are ok just set the image size
Me.imgQ.Height = originalH
Me.imgQ.Width = originalW
End If
I also have this javascript code (added a small bit of image size to get rid of scroll bars) above to display the image if its clicked and called with this
mike7510uk
Member
716 Points
334 Posts
Re: get image from database, resize and display
Jul 25, 2011 11:34 AM|LINK
I am having problems with the "Content type" part of this. I dont have that field in my DB table and dont want to limit the user to only being able to upload .jpg for example.
How can we let the user upload any image type and then display them in this way?
mike7510uk
Member
716 Points
334 Posts
Re: get image from database, resize and display
Jul 25, 2011 12:09 PM|LINK
Here is my DB table structure..
ID - autonumber
adtext - text
imagename - text
imagevalue - OLE Object
I have sorted the image upload and it works well. I now need to get the image from the table and display it in a image controller (not gridview or anything)
how can i do this?
TFA
Member
38 Points
13 Posts
Re: get image from database, resize and display
Feb 29, 2012 02:21 AM|LINK
For anyone needing to do what I needed here is what I did
I needed to limit the image size by that i mean limit the max heigh and max width (resize) and display here is the code that works fine for me, there is probably a simpler way but this works
'This is for resizing the image
Dim MaxHeight As Integer = 200
Dim MaxWidth As Integer = 800
Dim newImage As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("images/" & YourImageFileName))
Dim originalH As Integer = newImage.Height
Dim originalW As Integer = newImage.Width
If originalH > MaxHeight Then
'Need to resize
Dim HDiff As Integer = originalH - MaxHeight
Dim PerChange = 1 - (HDiff / originalH)
'Now we need to check if the new width is still bigger than max
Dim newWidth = originalW * PerChange
If newWidth > MaxWidth Then
'now we need to resize again
Dim Wdiff = newWidth - MaxWidth
Dim WPerChange = 1 - Wdiff / MaxWidth
Me.imgQ.Height = MaxHeight * WPerChange
Me.imgQ.Width = MaxWidth
Else
Me.imgQ.Height = MaxHeight
Me.imgQ.Width = originalW * PerChange
End If
ElseIf originalW > MaxWidth Then
'now we need to resize again
Dim Wdiff = originalW - MaxWidth
Dim WPerChange = 1 - Wdiff / MaxWidth
Me.imgQ.Height = MaxHeight * WPerChange
Me.imgQ.Width = MaxWidth
Else
'otherwise we are ok just set the image size
Me.imgQ.Height = originalH
Me.imgQ.Width = originalW
End If
<script type="text/javascript" language="javascript">
function DisplayNewImageInWidnow(imagectl) {
Field = imagectl;
html = "<HTML><HEAD>"
+ "</HEAD><BODY LEFTMARGIN=0 "
+ "MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>"
+ "<IMG src='"
+ Field.src
+ "' BORDER=0 NAME=image "
+ "onload='window.resizeTo(document.image.width+40,document.image.height+110)'>"
+ "</CENTER>"
+ "</BODY></HTML>";
popup = window.open('', 'image', 'toolbar=0,location=0,directories=0,menuBar=0,scrolling=0,left=0,top=0');
popup.document.open();
popup.document.write(html);
popup.document.focus();
popup.document.close();
}
</script>
I also have this javascript code (added a small bit of image size to get rid of scroll bars) above to display the image if its clicked and called with this
<asp:Image ID="imgQ" runat="server" ToolTip="Click view image's original size" onclick="return DisplayNewImageInWidnow(this);" ImageAlign="Middle" style="margin-left: 0px; cursor:pointer" />
Hope this helps you out