Bug 11285 - Picture.createfromstream failing
Summary: Picture.createfromstream failing
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.4.x
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Radek Doulik
Depends on:
Reported: 2013-03-20 10:29 UTC by Allie Miller
Modified: 2017-06-28 21:25 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Output (48.62 KB, image/png)
2013-03-20 10:29 UTC, Allie Miller

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Allie Miller 2013-03-20 10:29:15 UTC
Created attachment 3663 [details]

I am having some problems drawing a picture on my canvas, in mono for android..
I do this: Picture thisImage = Picture.CreateFromStream(Streams);
Streams is read of the type System.IO.Memorystream

When I start writing the overload, for createfromstream, I get this message:
"stream: to be added"

No test project can be added, since the image data is coming from a separate unit we communicate with, via a socket connection, and then transfer the stream.
The project, with almost excact the same code, is running on a pc. Running either linux with mono, or windows.. so I know the communication is fine, and I transfer the data correctly.
I can also see in debug mode, that the stream is filled with data.

But when I call the Picture.createfromstream() function, it just stops.

My code looks like this..:
The last line, is a canvas type, drawing the actual picture, after reading it from stream.. I use this canni variable, to draw all sorts of things…
Paths, circles, arcs, pies….. you name it. But when I get to drawing a picture, it just skips the rest..
I try to create the picture variable in the first line, but when I do, it just skips the rest…

// now create an Image from this stream
Picture thisImage = Picture.CreateFromStream(Streams[id_image]);

// now put the Image in the rectangular area
canni.DrawPicture(thisImage, new RectF(ix1, iy1, ix2, iy2));

in my windows application, it looks like this.
Difference is, that in windows, I can use System.drawing classes, in android I must use Android.Graphics

// now create an Image from this stream
System.Drawing.Image thisImage = System.Drawing.Image.FromStream(Streams[id_image]);
// now put the Image in the rectangular area
canv.Graphics.DrawImage( thisImage , ix1, iy1, ix2-ix1 , iy2-iy1 );

the streams array is filled by a function that looks like this.
It’s exactly the same in both android and windows..

- Some picture is put into a stream, and sent from some PLC to the client program I am writing.. when I receive it, I put it into a Image format, and draw it on a canvas.

public unsafe void make_an_image( int id, int len, byte* p_byte )
int i;
byte b;

if ( id == 0 ) return;
if ( len == 0 ) return;

// create a stream which includes the image
MemoryStream thisStream = new MemoryStream();

thisStream.Seek( 0 , SeekOrigin.Begin );
for ( i = 0; i < len; i++ )
b = *p_byte;
thisStream.WriteByte( b );

Streams[id] = thisStream;

Comment 2 esr 2013-04-03 04:40:18 UTC
Object reference not set to an instance of an object
  at (wrapper delegate-invoke) 
<Module>:invoke_intptr__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[])
at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms)
 [0x00000] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:763 

  at Android.Graphics.Picture.CreateFromStream (System.IO.Stream stream) [0x00034] 
in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.Graphics.Picture.cs:157 
 at AMC_500_HMI_9998.AMC_Drawing.draw_image_by_points (Android.Graphics.Canvas canvas) [0x00085] in C:\Users\esr\workspace\AMC 500 HMI 9998\AMC 500 HMI 9998\Drawing.cs:2194 
  at AMC_500_HMI_9998.AMC_Drawing.draw (Android.Graphics.Canvas canv) 
[0x00696] in C:\Users\esr\workspace\AMC 500 HMI 9998\AMC 500 HMI 9998\Drawing.cs:6859 }