Click here to Skip to main content
15,946,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every body ,

assuming that I have in aspx

<asp:Image ID="Image1" runat="server" />

and In .vb

Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Drawing.Imaging

Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mem As MemoryStream = New MemoryStream
mem = fnx("rodolphe")
Catch ex As Exception
If Not mem Is Nothing Then
mem.Dispose() : mem = Nothing
End If

End Try

End Sub

Protected Function fnx(ByVal str As String) As MemoryStream
Dim ms As MemoryStream = New MemoryStream()
Dim bitmap As New Bitmap(1, 1)
Dim font As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel)
Dim graphics As Graphics = graphics.FromImage(bitmap)
Dim width As Integer = CInt(graphics.MeasureString(str, font).Width)
Dim height As Integer = CInt(graphics.MeasureString(str, font).Height)
bitmap = New Bitmap(bitmap, New Size(width, height))
graphics = graphics.FromImage(bitmap)
graphics.SmoothingMode = SmoothingMode.HighQuality
graphics.TextRenderingHint = TextRenderingHint.AntiAlias
graphics.DrawString(str, font, New SolidBrush(Color.FromArgb(5, 5, 5)), 0, 0)
bitmap.Save(ms, ImageFormat.Jpeg)
Return ms
Catch ex As Exception
End Try
End Function
End Class

how to can I transform the memorystream to Image src
thanks. . .
[no name] 23-Aug-13 7:24am    
Geoffrey Boult 6-Nov-13 10:50am    
Solution 2 is fantastic! - thanks so much. I've been trying to find a solution to this problem for months!
gchq 5-Dec-14 11:47am    
Great solution - have done this for years in Winforms and WPF, but was driving me batty in

hii i have implemented this things as below please check code

here we have UploadeImage() function which return image Bytes

MemoryStream ms = new MemoryStream(UploadImage());
img2.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray(), 0, ms.ToArray().Length);
Share this answer
manojmadhuranga 16-Jan-14 23:48pm    
What a great...! thanks for solving my problem...good luck..Happy coding and thanks again..!
rage_86 13-Feb-14 7:04am    
Thank you,Thank you,Thank you,Thank you!!! I try this for 2 days to paint one table with one object list, i can't save in a physical path, and always had an exception, this save me!
I don't know about the syntax in, but following code of C# is almost equal to what you are trying to achieve. You can use some code converter to convert the code in

using (MemoryStream memoryStream = ...)
var imageSource = new BitmapImage();
imageSource.StreamSource = memoryStream;

// Assign the Source property of your image
image.Source = imageSource;
Share this answer

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