Load dynamic image with through handler

Stimulsoft Reports.NET discussion
algarveweb
Posts: 11
Joined: Thu Jan 25, 2007 3:30 pm
Location: Portugal

Load dynamic image with through handler

Post by algarveweb »

Hi

I usually use an Image Handler to create thumbnails for my web-sites which works OK.

I am trying to do the same with Stimulreport but it does not work:

Line 181: Dim my_img_1 As StiImage = my_rep.GetComponents()("img_1")
Line 182: my_img_1.Image = "imgHandler.ashx?h=255&w=340&img=app_content_prop_photo/" & my_dtr("PHOTO") & ".jpg"

Line 182 causes the error.

Any ideas?

Thanks, Mike.

BTW Any news on the Express Edition?
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Load dynamic image with through handler

Post by Brendan »

Instead of the Image property have you tried the ImageURL property?
algarveweb
Posts: 11
Joined: Thu Jan 25, 2007 3:30 pm
Location: Portugal

Load dynamic image with through handler

Post by algarveweb »

Brendan wrote:Instead of the Image property have you tried the ImageURL property?
Thanks, but that would not work since the image is actually hold in memory.

I also tried ImageToDraw, but to no avail.

Mike
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Load dynamic image with through handler

Post by Edward »

Please read the following topic

http://forum.stimulsoft.com/Default.aspx?g=posts&t=1207

Thank you.
algarveweb
Posts: 11
Joined: Thu Jan 25, 2007 3:30 pm
Location: Portugal

Load dynamic image with through handler

Post by algarveweb »

Thanks.

I adapted to VB, errors are in bold:

Dim bmp As Image = Nothing
Dim stream As System.IO.FileStream = Nothing
Dim fileName As String = "imgHandler.ashx?h=255&w=340&img=app_content_prop_photo/" & my_dtr("PHOTO") & ".jpg"
Try
stream = New System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim buf As Byte() = New Byte(stream.Length) {}
stream.Read(buf, 0, buf.Length)
bmp = Image.FromStream(New System.IO.MemoryStream(buf))
Catch
Finally
If Not stream Is Nothing Then
stream.Close()
End If
End Try
Image1.Image = bmp

Any ideas?

BTW the report is compiled as an dll.

Mike
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Load dynamic image with through handler

Post by Edward »

algarveweb wrote:Thanks.

I adapted to VB, errors are in bold:
Please modify the code as follows:

Dim bmp As Image = Nothing
Dim stream As System.IO.FileStream = Nothing
Dim fileName As String = "imgHandler.ashx?h=255&w=340&img=app_content_prop_photo/" & my_dtr("PHOTO") & ".jpg"
Try
stream = New System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim buf As Byte() = New Byte(stream.Length-1) {}
stream.Read(buf, 0, buf.Length)
bmp = Image.FromStream(New System.IO.MemoryStream(buf))
Catch
Finally
If Not stream Is Nothing Then
stream.Close()
End If
End Try
Image1.Image = bmp

Also please check that the fileName contains correct link to the image file.

Thank you.
algarveweb
Posts: 11
Joined: Thu Jan 25, 2007 3:30 pm
Location: Portugal

Load dynamic image with through handler

Post by algarveweb »

Thanks, but the what is Image.FromStream and Image1 which are the errors?

Mike


Image

Image
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Load dynamic image with through handler

Post by Edward »

Image1 - it is a StiImage component inside the report page.

Image - it is a .Net class in a namespace Image.Drawing

Please check the path to the images. Is it correct?

Thank you.

algarveweb
Posts: 11
Joined: Thu Jan 25, 2007 3:30 pm
Location: Portugal

Load dynamic image with through handler

Post by algarveweb »

Thanks, the report opens now (directly in PDF) but the Images are empty:

http://www.mod.algarveweb.com/expose_dll.aspx

The filename is correct since it shows in normal web-forms.

Here is my update code:

Dim bmp As System.Drawing.Image = Nothing
Dim stream As System.IO.FileStream = Nothing
Dim fileName As String = "imgHandler.ashx?h=255&w=340&img=app_content_prop_photo/" & my_dtr("PHOTO") & ".jpg"
Try
stream = New System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim buf As Byte() = New Byte(stream.Length - 1) {}
stream.Read(buf, 0, buf.Length)
bmp = System.Drawing.Image.FromStream(New System.IO.MemoryStream(buf))
Catch
Finally
If Not stream Is Nothing Then
stream.Close()
End If
End Try
Dim my_img_1 As StiImage = CType(my_rep.GetComponents()("img_1"), StiImage)
my_img_1.Image = bmp

Please advice, thanks, Mike.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Load dynamic image with through handler

Post by Edward »

Loading image from URL into stream not always possible.

So please load images via the following static (sharing) method:

Code: Select all

Stimulsoft.Base.Drawing.StiImageFromURL.LoadBitmap(ByVal url As String)
Thank you.
Post Reply