hi everyone. I have written a program that convert from color image to gray image in asp.net with visual basic, but I have a problem am new in asp.net and I want to display the gray image but I don't know how. please help me. this is a code.

If (FileUpload1.HasFile) Then
            FileUpload1.SaveAs(MapPath(FileUpload1.FileName))
            Image1.ImageUrl = FileUpload1.FileName
        End If
        Dim current As Bitmap = New Bitmap(Server.MapPath(Image1.ImageUrl))
        Dim pic1 As Bitmap = New Bitmap(current)
        Dim gray As Bitmap = New Bitmap(pic.Width - 1, pic.Height - 1)
        For a = 0 To (pic1.Width) - 1
            For b = 0 To (pic1.Width) - 1
                Dim c As Color = pic1.GetPixel(a, b)
                Dim rx As Single = c.R
                Dim g As Single = c.G
                Dim b1 As Single = c.B
                Dim d As Integer = CInt(rx * 0.3 + g * 0.5 + b1 * 0.11)
                gray.SetPixel(a, b, Color.FromArgb(d, d, d))
            Next
        Next

Recommended Answers

All 2 Replies

Maybe this could help? It's someone who made a basic webpage and implemented ASP.NET into it. If you click the button the color of what I think is the muslim prayer buildings will change to gray by ASP function that has also been presented and explained. I looked at your code and the code on website, they're similiar in some way, but are not exactly same.

What problem are you having? From what I see of your code sample, the original uploaded image might display (though I'm not sure what URL is getting generated.)

The changes you make to the Bitmap are all happening in memory. They are not altering the image file on the web server. Once you are done with the transformation, you need to put the resulting image someplace the web server can reach it -- such as saving it into "~/images/gray/" and then pointing Image1 to that URL.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.