Solved

VB .net - Writing an images ImageURL using a webservice....

Posted on 2004-03-31
1
1,167 Views
Last Modified: 2012-06-22
Hi,

I have a web service that returns an image in a byte array: code below:

***************************************************************************************
<WebMethod()> _
    Public Function MakeChartPreview() As Byte()

        'Dimension variable as byte array.
        'Dim ImageStream As Stream = New MemoryStream

        'If the image is generated successfully then return the byte array to the consumer.
        'If (MakeImage(ImageStream)) Then
        'Return ImageStream
        'End If

        'Dimension variable as type 'Bitmap'.
        Dim NewBitmap As Bitmap = Nothing

        'Dimension variable as type 'Graphics'. This provides the drawing space
        Dim G As Graphics = Nothing

        'Dimension variable as type 'Pen'
        Dim BluePen As Pen

        'Create the bitmap
        NewBitmap = New Bitmap(500, 500) 'Bitmap dimensions to be determined from Datastore.

        'Get the graphics workspace from the bitmap 'NewBitmap'
        G = Graphics.FromImage(NewBitmap)

        'Instantiate the 'Pen' object.
        BluePen = New Pen(Color.Blue, 2)

        'Draw a blue rectangle
        G.DrawRectangle(Pens.Blue, New Rectangle(88, 110, 100, 15))

        Dim MemStream As New MemoryStream

        ' Save the bitmap in the form required
        NewBitmap.Save(MemStream, Jpeg)

        Return MemStream.GetBuffer()

    End Function
***************************************************************************************

In the webpage that calls the function i have:
***************************************************************************************
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        'Dimension variable type as the webservice type.
        Dim oWSCharting As WR_WSCharting.WSCharting

        'Instantiate new instance of the web service object.
        oWSCharting = New WR_WSCharting.WSCharting

        Dim sbyte As Byte() = oWSCharting.MakeChartPreview
        Dim mStream As New MemoryStream(sbyte)
        Dim sbuffer = mStream.GetBuffer()

        Response.ContentType = "image/jpeg"

       
       image.imageURL = [[IMAGE FROM THE WEB SERVICE]]

      ######
      What needs to be in here?
      ######

    End Sub
***************************************************************************************


What am I missing in the Page_Load above? Please note that I don't want to have to write the file to disk at any point, if there is a way not to.

Cheers

AArnie.
0
Comment
Question by:AArnie
1 Comment
 
LVL 12

Accepted Solution

by:
farsight earned 250 total points
ID: 10725266
Option 1:
The way HTTP works is that the web page is downloaded with one GET of a URL.  Each image is downloaded with a separate GET.  This means that each image shown on a regular web page MUST have a URL.

The trick is that each URL does not have to have a file associated with it.  You can put a URL like http:\\www.mysite.com/myapp/image.aspx?7734819 for the image.  Then you make a page, image.aspx, that uses the parameter on the URL to generate and return the correct image over HTTP.

In summary, there are two pieces:
(1) In a regular ASPX web page, write a URL with an imageID (e.g. in an <img> tag).
(2) Write an image generator ASPX page called from that URL to generate and return images based on the imageID.
(3) (Optional) If there's important information associated with each image, information that you need to properly generate it, you'll need to move that information from the regular web page to the image generator page.  Probably Session data would work, but a database might be effective, too.

It seems like you have those ideas in your example, but you're trying to combine them in one page, as far as I can tell.

Option 2:
It is possible to have javascript on the client page call the XML Web Service and get the result directly.
[ See book by Jeff Webb: "Developing Web Application With Microsoft Visual Basic.NET And Microsoft Visual C#.NET, Second Edition", pages 392-394 ]
I don't know jscript well enough to know how you'd get the bytestream for the image into the image control.

Option 3:
Someone's doing a similar task here in this code. [C#, but not hard to translate]
http://winbeta.verio.net/Portal/ImageResizer.html

It appears that the key lines are:
    Response.ContentType = "image/jpeg";
    newImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
though the example shows considerable setup before calling them.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now