473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

JavaScriptConverter for Bitmaps

Hi,

I've got a webservice that returns a System.Drawing.Image. I'm calling the
webservice via AJAX all goes well but my JSON converter seralize method
gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred in
mscorlib.dll

Hope you can help.
TIA

MattC - code bellow

Service:

[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:

TestingGround.AJAXServices.LocalChartService.Chart DataTwo(SuccessCallBack,
FailedCallback);

And the callback on success

function OnCompleteImageService(results)
{
var obj = Sys.Serialization.JavaScriptSerializer.deserialize (results);
document.getElementById('ImageService').src = obj;
}

And my JSON Converter

class AjaxImageConvert : JavaScriptConverter
{

public override IDictionary<string, objectSerialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;

//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;

Dictionary<string, objectresult = new Dictionary<string,
object>();

result["CustomImage"] = i;

return result;
}
return new Dictionary<string, object>();
}

public override IEnumerable<TypeSupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}

public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}

}
And registered

<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>
May 11 '07 #1
4 1671
javascript does not have a bitmap datatype (nor binary) so there is
nothing to serialize to. the normal way would be to base64 encode the
bitmap to string, then send the string.

why are you passing an image thru ajax? javascript can not display a
bitmap directly anyway. javascript can create a new Image() and set its
url to fetch from the server, or set the src of an <imgto display an
image. no ajax required.

-- bruce (sqlwork.com)

MattC wrote:
Hi,

I've got a webservice that returns a System.Drawing.Image. I'm calling the
webservice via AJAX all goes well but my JSON converter seralize method
gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred in
mscorlib.dll

Hope you can help.
TIA

MattC - code bellow

Service:

[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:

TestingGround.AJAXServices.LocalChartService.Chart DataTwo(SuccessCallBack,
FailedCallback);

And the callback on success

function OnCompleteImageService(results)
{
var obj = Sys.Serialization.JavaScriptSerializer.deserialize (results);
document.getElementById('ImageService').src = obj;
}

And my JSON Converter

class AjaxImageConvert : JavaScriptConverter
{

public override IDictionary<string, objectSerialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;

//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;

Dictionary<string, objectresult = new Dictionary<string,
object>();

result["CustomImage"] = i;

return result;
}
return new Dictionary<string, object>();
}

public override IEnumerable<TypeSupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}

public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}

}
And registered

<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>

May 11 '07 #2
Yeah I tried the base64 route but IE ignores the data:image/gif;base64 part
and is limted to 1024bytes.

I can do it using using the src set to the webservice but IE only makes 2
HTTP requests at the same time. I thought possibly that the AJAX
webrequests would not be bound by IE's request limit and allow, say all 20
requests to fire off to the webservice.

MattC
"bruce barker" <no****@nospam.comwrote in message
news:eF****************@TK2MSFTNGP04.phx.gbl...
javascript does not have a bitmap datatype (nor binary) so there is
nothing to serialize to. the normal way would be to base64 encode the
bitmap to string, then send the string.

why are you passing an image thru ajax? javascript can not display a
bitmap directly anyway. javascript can create a new Image() and set its
url to fetch from the server, or set the src of an <imgto display an
image. no ajax required.

-- bruce (sqlwork.com)

MattC wrote:
>Hi,

I've got a webservice that returns a System.Drawing.Image. I'm calling
the webservice via AJAX all goes well but my JSON converter seralize
method gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred
in mscorlib.dll

Hope you can help.
TIA

MattC - code bellow

Service:

[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:

TestingGround.AJAXServices.LocalChartService.Char tDataTwo(SuccessCallBack,
FailedCallback);

And the callback on success

function OnCompleteImageService(results)
{
var obj =
Sys.Serialization.JavaScriptSerializer.deserializ e(results);
document.getElementById('ImageService').src = obj;
}

And my JSON Converter

class AjaxImageConvert : JavaScriptConverter
{

public override IDictionary<string, objectSerialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;

//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;

Dictionary<string, objectresult = new
Dictionary<string, object>();

result["CustomImage"] = i;

return result;
}
return new Dictionary<string, object>();
}

public override IEnumerable<TypeSupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}

public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}

}
And registered

<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>

May 11 '07 #3
ajax is limted to 2 concurrent requests also (IE treats it as another
http request). this is to be friendly to web servers.

note: if you use session with your webservice you will be limited to one
request at a time as requests for the same session are queued on the
server side.

if you want performance, iis serves up images a lot faster then asp.net
can.

-- bruce (sqlwork.com)

MattC wrote:
Yeah I tried the base64 route but IE ignores the data:image/gif;base64 part
and is limted to 1024bytes.

I can do it using using the src set to the webservice but IE only makes 2
HTTP requests at the same time. I thought possibly that the AJAX
webrequests would not be bound by IE's request limit and allow, say all 20
requests to fire off to the webservice.

MattC
"bruce barker" <no****@nospam.comwrote in message
news:eF****************@TK2MSFTNGP04.phx.gbl...
>javascript does not have a bitmap datatype (nor binary) so there is
nothing to serialize to. the normal way would be to base64 encode the
bitmap to string, then send the string.

why are you passing an image thru ajax? javascript can not display a
bitmap directly anyway. javascript can create a new Image() and set its
url to fetch from the server, or set the src of an <imgto display an
image. no ajax required.

-- bruce (sqlwork.com)

MattC wrote:
>>Hi,

I've got a webservice that returns a System.Drawing.Image. I'm calling
the webservice via AJAX all goes well but my JSON converter seralize
method gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred
in mscorlib.dll

Hope you can help.
TIA

MattC - code bellow

Service:

[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:

TestingGround.AJAXServices.LocalChartService.Cha rtDataTwo(SuccessCallBack,
FailedCallback);

And the callback on success

function OnCompleteImageService(results)
{
var obj =
Sys.Serialization.JavaScriptSerializer.deseriali ze(results);
document.getElementById('ImageService').src = obj;
}

And my JSON Converter

class AjaxImageConvert : JavaScriptConverter
{

public override IDictionary<string, objectSerialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;

//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;

Dictionary<string, objectresult = new
Dictionary<string, object>();

result["CustomImage"] = i;

return result;
}
return new Dictionary<string, object>();
}

public override IEnumerable<TypeSupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}

public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}

}
And registered

<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>

May 11 '07 #4
m
Problem is the images don't exist until requested, i.e they are generated
from some backend stats analysis.
I thought of maybe using a custom handler that implements IHttpAsyncHandler
and set the maxconnections section of the web.config to a higher number.

Would that do it. I really want to try and get the page (which has any where
up to 10 of these images) to be as quick to download.

Is there anyway to break to 2 request barrier. I have full control over
settings on the web app and webservice.

Thanks for your help so far.

MattC

"bruce barker" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
ajax is limted to 2 concurrent requests also (IE treats it as another http
request). this is to be friendly to web servers.

note: if you use session with your webservice you will be limited to one
request at a time as requests for the same session are queued on the
server side.

if you want performance, iis serves up images a lot faster then asp.net
can.

-- bruce (sqlwork.com)

MattC wrote:
>Yeah I tried the base64 route but IE ignores the data:image/gif;base64
part and is limted to 1024bytes.

I can do it using using the src set to the webservice but IE only makes 2
HTTP requests at the same time. I thought possibly that the AJAX
webrequests would not be bound by IE's request limit and allow, say all
20 requests to fire off to the webservice.

MattC
"bruce barker" <no****@nospam.comwrote in message
news:eF****************@TK2MSFTNGP04.phx.gbl...
>>javascript does not have a bitmap datatype (nor binary) so there is
nothing to serialize to. the normal way would be to base64 encode the
bitmap to string, then send the string.

why are you passing an image thru ajax? javascript can not display a
bitmap directly anyway. javascript can create a new Image() and set its
url to fetch from the server, or set the src of an <imgto display an
image. no ajax required.

-- bruce (sqlwork.com)

MattC wrote:
Hi,

I've got a webservice that returns a System.Drawing.Image. I'm calling
the webservice via AJAX all goes well but my JSON converter seralize
method gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred
in mscorlib.dll

Hope you can help.
TIA

MattC - code bellow

Service:

[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:

TestingGround.AJAXServices.LocalChartService.Ch artDataTwo(SuccessCallBack,
FailedCallback);

And the callback on success

function OnCompleteImageService(results)
{
var obj =
Sys.Serialization.JavaScriptSerializer.deserial ize(results);
document.getElementById('ImageService').src = obj;
}

And my JSON Converter

class AjaxImageConvert : JavaScriptConverter
{

public override IDictionary<string, objectSerialize(object
obj, JavaScriptSerializer serializer)
{
Bitmap i;

//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;

Dictionary<string, objectresult = new
Dictionary<string, object>();

result["CustomImage"] = i;

return result;
}
return new Dictionary<string, object>();
}

public override IEnumerable<TypeSupportedTypes
{
get { return new ReadOnlyCollection<Type>(new
List<Type>(new Type[] { typeof(Bitmap) })); }
}

public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}

}
And registered

<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>
May 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brad Smalling | last post by:
Does anyone know if there is a reason to prefer bitmaps over icons (or vice-versa) when populating image lists? I've always favored icons because of their built-in transparency (although I've...
13
by: Jeff Melvaine | last post by:
I note that I can write expressions like "1 << 100" and the result is stored as a long integer, which means it is stored as an integer of arbitrary length. I may need to use a large number of...
1
by: Mark Evans | last post by:
I have a dialog box and on it I want to display a bitmap, which will change at various times during the program. My problem is that the bitmaps will not be the same each time. I want the user to...
4
by: Nathan | last post by:
Hello, I'm needing some advice: I have an app for which I've built a timer out of multiple bitmaps--a clock with a moving hands. I've saved each hand position (1 second, 2 seconds, etc.) as a...
1
by: John | last post by:
I have 76 bitmaps (640 x 480) and need to combine them together to form a big one (about 3840 x 2880). Those 76 bitmaps overlap each other with a small portion. Is there any way to do it? Thanks.
1
by: Peter Stojkovic | last post by:
What is the correct way to move BITMAPS and drawings inside a windows-forms from one project to another project. The problem is the following row: Dim resources As...
2
by: Mike | last post by:
Hello everybody. I am drawing a country map that consists of 149 municipality bitmaps, each around 25 Kb. I draw it onto the in-memory bitmap, then draw it on the picture box. I use C++, but...
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I need to combine several bitmaps together to form a single bitmap. Can anyone show me some similar sample code? Thanks. AJ
1
by: nkumarin001 | last post by:
Hi, Can anyone help me in this matter:- When i was studying locally managed tablespaces i came across bitmaps that are used in locally managed tablespaces it stated that:- "Locally...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.