Page 1 of 2
Load dynamic image with through handler
Posted: Mon Mar 24, 2008 5:56 am
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?
Load dynamic image with through handler
Posted: Mon Mar 24, 2008 6:58 am
by Brendan
Instead of the Image property have you tried the ImageURL property?
Load dynamic image with through handler
Posted: Mon Mar 24, 2008 8:32 am
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
Load dynamic image with through handler
Posted: Mon Mar 24, 2008 8:40 am
by Edward
Load dynamic image with through handler
Posted: Mon Mar 24, 2008 11:25 am
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
Load dynamic image with through handler
Posted: Tue Mar 25, 2008 7:28 am
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.
Load dynamic image with through handler
Posted: Tue Mar 25, 2008 7:51 am
by algarveweb
Thanks, but the what is
Image.FromStream and
Image1 which are the errors?
Mike

Load dynamic image with through handler
Posted: Tue Mar 25, 2008 8:07 am
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.
Load dynamic image with through handler
Posted: Tue Mar 25, 2008 9:08 am
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.
Load dynamic image with through handler
Posted: Wed Mar 26, 2008 3:38 am
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.