How to write a video from streaming bytearray - .net-4.8

I want to get a video file from a byte array which I stored in an array.
I am creating a MemoryStream object and passing the bytearray there. as like this:
MemoryStream ms = new MemoryStream(arrByte);
After that i am creating an object of bitmap and passing the memorystream instance to this object. as like this:
Bitmap bm = new Bitmap(ms);
But due to some reason i am not able to convert it to bitmap. this is the error I am getting: as like this: error: 'Parameter is not valid.'
To overcome this error i tried to use: ms.Position = 0;, ms.Seek(0, SeekOrigin.Begin); but they dont work. Can we convert streaming bytearray of video to bitmap ??
We are using this article to overcome this error but it didnot work:
Parameter is not valid error when creating image from byte[] in c#

Related

64k limit for NotesJSONNavigator?

I'm currently testing the new Domino V10 LotusScript NotesJSONNavigator classes, and trying to parse long strings using this code:
dim session as New NotesSession
Dim jsonReader as NotesJSONNavigator
Dim stream as NotesStream
Set stream = session.CreateStream
stream.WriteText("*** Populate stream with long JSON here ***")
stream.Position = 0
Set jsonReader = session.CreateJSONNavigator(stream.ReadText)
Once the stream contains more than 64k of text, the final line of code produces an error as follows:
"Unable to Parse JSON string:
Missing a closing quotation mark in string, offset 65535."
If there is a 64k limit, this is a real shame, because the performance of NotesJSONNavigator appears to be very good. Is there any workaround for this if so?

Converting ByteArray to base64 on Windows Phone

I'm facing a tremendous problem using the base64 convertor. I am calling the standard base64 convert function on Windows Phone but the result always differs from the one expected on web converters and many other on Android and iOS platforms.
Basically I take an Image from the gallery or Camera and convert it to byte array. The the byte array is passed to convert method.
Convert.ToBase64String(bytearray);
The resulting string should look like this :
/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wgARCAADAAMDAREAAhEBAxEB/8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vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD7d+FP7cn7UvwM+F/w5+Cfws+KJ8LfDH4PeBPCXwt+HPhn/hCvh3rf/CO+BPh/oNh4T8I6H/bPiLwlq/iDV/7J0DSdPsDqmu6rqes6gbf7XqmoXt9NPcylFFfy7/b+e/8AQ6zb/wAOOM/+XH+2X/EKfC7/AKNtwD/4h3Dv/wA7j//Z
It differs not so much, but it differs.
The right one is generated using PHP. And the Windows phone is generated usingUNICODE encoding on image.
Does anyone know how where could be a problem?
Try using this piece of code using the WriteableBitmap:
public string GetBase64Encoding(BitmapImage imageUrl)
{
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
if (imageUrl == null)
{
}
else
{
WriteableBitmap wbitmp = new WriteableBitmap((BitmapImage)imageUrl);
wbitmp.SaveJpeg(ms, 46, 38, 0, 100);
bytearray = ms.ToArray();
}
}
string str = Convert.ToBase64String(bytearray);
return str;
}
For more you could refer this too:
Convert base64 string to image in C# on Windows Phone
Hope it helps!

problems reading int from bytearray

This is my first question, so do not judge strictly.
I have an object that I'm getting from php server to as3(flash) client. That object is AMF encoded, so I write server response to ByteArray:
var ba:ByteArray = new ByteArray();
ba.writeUTFBytes( rawData );
and than I'm reading object from ByteArray:
ba.position = 0;
var response:Object = ba.readObject();
Part of object contains such data:
{
'money' : 900
}
And when reading object from ByteArray, I get a seven-digit number ~ 1824344 instead of 900. But when I get form server String '900' or int value equals 100 - data reads correctly.
Has someone had such a problem?
You have to read the same way you wrote. If you write something using writeUTFBytes(), you have to read it using readUTFBytes().
In this case you should use writeObject() and readObject() because you are writing pure Object but not String.

Parsing url parameters in a String

I am using the example code in flash. I want a single variable and not the whole text.
I have a dynamic textfield called OUTPUT on the stage.
var fl_TextLoader:URLLoader = new URLLoader();
var fl_TextURLRequest:URLRequest = new URLRequest("http://www.testing.com/Christmas.txt");
fl_TextLoader.addEventListener(Event.COMPLETE, fl_CompleteHandler);
function fl_CompleteHandler(event:Event):void
{
var textData:String = new String(fl_TextLoader.data);
OUTPUT.text = textData;
}
fl_TextLoader.load(fl_TextURLRequest);
The Christmas text file contents:
Var1=Jesus&Var2=Mary&Var3=Christmas
The OUTPUT comes out with the whole string. How do I get the url parameter values separately?
Like OUTPUT.text = textData.Var1; (<--- But this does not work.)
The .data property is just a string, the raw data returned by the HTTP call, so you will have to parse the variable-value pairs, either using simple .split() on the strings or using the URLVariables object, that can do the parsing for you:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#decode()

Silverlight json won't serialize

I have been trying to serialize some json data in Silverlight. I am using the following code
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(stacks.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, stacks);
StreamReader reader = new StreamReader(ms);
string json = reader.ReadToEnd();
to attempt the serialization. It does not work. It was the only example I could find that did not produce errors in Visual Studio. I am passing a list of custom coded objects (stacks). When I try to view the results I am getting a blank string. Anyone got some ideas on how to point me in the right direction?
The stream cursor is pointing to the end (after everything was written). Add the line "ms.Position = 0;" before creating the StreamReader.