Solved

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

Posted on 2004-03-31
1
1,177 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a Dropdown list with sub group 10 43
How to set focus on a dynamic control 18 52
Error in Visual Project 10 48
Need Help With GDI+ in VB.Net 8 40
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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