?
Solved

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

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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