Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing a Windows 8.1 silverlight app . For my application I have to take screenshot of present screen and send the screenshot to server . For this I converted the image to byte array. The problem is the converted byte array containing bytes from 0 to 255 but i want -127 to 127 . How to do this.

sample of byte array I am getting is

255,216,255,224,0,16,74,70,73,70,0,1,1,1,0,96,0,96,0,0,255,219,0,67,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,255,219,0,67,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,255,192


required format is

-119,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,18,0,0,1,19,8,6,0,0,0,-94,7,48,71,0,0,0,4,115,66,73,84,8,8,8,8,124,8,100,-120,0,0,32,0,73,68,65,84,120,-100,-20,-35,-55,-113,-100,121,-98,-33,-9,-9,-77,-58,-66,-28,-66,49,51,-103,-36,-117,-59,98,85,-85,87,77,25,-93,-42,-76,0,73,-10,-95,-95,-117,5,75,23,-51,-63,103,-63,-14,-67,-83,-77,1,13,12,-1,3,-126,14,51,48,96,-7,96,-40,24,75,-16,-12,-72,87,77,87,-41,-50,-30,82,44,46,73,-26,-58,92,35,99,-113,120,-30,-39,124,72,38,-101,85,77,22,-103


ScreenShot taking and Converting to bytes code

WriteableBitmap bmp = new WriteableBitmap(480, 696);
               bmp.Render(LayoutRoot, null);
               bmp.Invalidate();
               var ms = new MemoryStream();
               bmp.SaveJpeg(ms, 480, 696, 0, 100);
               ms.Seek(0, SeekOrigin.Begin);
               imagebytes = ms.ToArray();


thank you,
Posted
Updated 6-Jan-15 18:49pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Jan-15 2:59am    
What is the pixel format? What are those -127 to +127 values, their meaning? You say "required format". This is not "format", this is a line with comma-separated numbers... :-)
What is the signed data type in this example of the array (if this is the array)?
—SA

1 solution

just Interpret/Convert the byte array as sbyte array on the Server side? Just apply you Offset or "Transformation" function before converting. Something like this:

C#
byte[] abyUnsigned = new byte[] { 0, 128, 255 };

sbyte[] abySigned = new sbyte[abyUnsigned.Length];
int iOffset = 128;
for (int i = 0; i < abyUnsigned.Length; i++)
{
    abySigned[i] = Convert.ToSByte(abyUnsigned[i] - iOffset);
    Console.WriteLine(abySigned[i]);

}

Btw. I'm wondering why you could have such a requirement (signed Image Bytes) - I'm puzzled...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900