Solved

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

Posted on 2004-03-31
1
1,180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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