[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

06/27/2007 at 09:54PM PDT, ID: 22663259
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

VB.NET - how to save an image into file folder

Asked by exceter in Web Images, Programming for ASP.NET

Tags: image, save, file

Hi,

1.
Why in the page when I click right button and want to try save an image I have the following message:
"The file type being save or retrieved has been blocked."

2.
How can I save images from web using VB.NET ?
I get images as:
<asp:Image ID="Image1" runat="server" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "fileID")) %>' />
         
Function FormatURL(ByVal strArgument) As String
      Return ("readrealimage2.aspx?id=" & strArgument)
End Function


<%@ Page Language="vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ODBC" %>
<HTML>
  <HEAD>
    <title>Read Record</title>  
    <script runat="server">
        Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim strImageID As String = Request.QueryString("id")
            ' Create Instance of Connection and Command Object
            Dim myConnection As OdbcConnection = New OdbcConnection(ConfigurationManager.ConnectionStrings("MySQLConnString1").ToString)
            ' Mark the Command as a SPROC
            Dim cmdStr As String = "select * from bmmsfile WHERE fileid=" & strImageID
            Dim myCommand As OdbcCommand = New OdbcCommand(cmdStr, myConnection)
            Dim _image, _newimage As System.Drawing.Image
            mycommand.CommandType = CommandType.Text
            Try
                myConnection.Open()
                Dim myDataReader As OdbcDataReader
                myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
                Do While (myDataReader.Read())
                    Response.ContentType = myDataReader.Item("fileid")
                    Dim bindata() As Byte = myDataReader.Item("data")
                    Dim Thumbnailbindata() As Byte = resizeImage(bindata)
                    Response.BinaryWrite(Thumbnailbindata)
                Loop
                myConnection.Close()
            Catch SQLexc As OdbcException
                Response.Write("Error occured while Generating Data. Error is " & SQLexc.ToString())
            End Try
        End Sub
       
        Public Function resizeImage(ByVal pic() As Byte) As Byte()
            ' Const THUMBNAIL_IMAGE_PATH As String = "C:\Thumbnails\Test.jpg"
            Const maxWidth As Integer = 500
            Const maxHeight As Integer = 500
            Dim inp As New IntPtr
            Dim imgHeight, imgWidth As Double
            Try
                Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(pic))
                Dim bm = New System.Drawing.Bitmap(image)
                Dim imgHres, imgVres As Single
                'Added this for testing - usually 96 dpi for every picture
                imgHres = bm.horizontalresolution
                imgVres = bm.verticalresolution
                imgHeight = bm.Height
                imgWidth = bm.Width
                If imgWidth > maxWidth Or imgHeight > maxHeight Then
                    'Determine what dimension is off by more
                    Dim deltaWidth As Double = imgWidth - maxWidth
                    Dim deltaHeight As Double = imgHeight - maxHeight
                    Dim scaleFactor As Double
                    If deltaHeight > deltaWidth Then
                        'Scale by the height
                        scaleFactor = maxHeight / imgHeight
                    Else
                        'Scale by the Width
                        scaleFactor = maxWidth / imgWidth
                    End If
                    imgWidth *= scaleFactor
                    imgHeight *= scaleFactor
                End If
                Dim w As Integer = Convert.ToInt32(imgWidth)
                Dim h As Integer = Convert.ToInt32(imgHeight)
                Dim imgbmp As System.Drawing.Image = bm.GetThumbnailImage(w, h, Nothing, inp)
                Dim ms As New System.IO.MemoryStream
                imgbmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
                Dim b(ms.Length - 1) As Byte
                ms.Position = 0
                ms.Read(b, 0, ms.Length)
                Return b


                'bitmap.Save(THUMBNAIL_IMAGE_PATH, Imaging.ImageFormat.Jpeg)

 

            Catch ex As Exception

            End Try
        End Function 'resizeImage
       
        Public Function ConvertTo(ByVal ImageArray As Byte()) As System.Drawing.Image
            '<summary>
            ' Convert a SQL Server database byte Array (byte array) to a Image.
            '</summary>
            Dim objMS As System.IO.MemoryStream
            Dim objImage As System.Drawing.Image
            objMS = New System.IO.MemoryStream(ImageArray)
            ' Convert the database byte array to a System Drawing Image.
            ConvertTo = System.Drawing.Image.FromStream(objMS)
           
        End Function
    </script>
  </HEAD>
  <body style="font: 10pt verdana">
    <form runat="server" id="Form1">
    </form>
  </body>
</HTML>
 
Keywords: VB.NET - how to save an image into…
 
Loading Advertisement...
 
[+][-]06/28/07 09:03 AM, ID: 19382041

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Web Images, Programming for ASP.NET
Tags: image, save, file
Sign Up Now!
Solution Provided By: stevekorb
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10/31/07 07:36 AM, ID: 20185825

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91