Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-31
1
Medium Priority
?
1,187 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 750 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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