Image 将带有Exif信息的图像从Windows Phone发送到Java服务器
我是Windows Phone(和StackOverflow tbh)编程新手。目前,我正在进行一项任务,该任务涉及将存储在Windows Phone存储器中的图像(带有Exif信息)发送到Java服务器。到目前为止,我已经成功地从Windows Phone客户端发送了字节流,并在Java端构建了映像,但是,Exif信息不知何故丢失了。我相信正是我在Windows Phone上发送信息的方式造成了这个问题。非常感谢您的帮助和指导! 以下是我在Windows Phone客户端上的代码:Image 将带有Exif信息的图像从Windows Phone发送到Java服务器,image,send,windows-phone,exif,java-server,Image,Send,Windows Phone,Exif,Java Server,我是Windows Phone(和StackOverflow tbh)编程新手。目前,我正在进行一项任务,该任务涉及将存储在Windows Phone存储器中的图像(带有Exif信息)发送到Java服务器。到目前为止,我已经成功地从Windows Phone客户端发送了字节流,并在Java端构建了映像,但是,Exif信息不知何故丢失了。我相信正是我在Windows Phone上发送信息的方式造成了这个问题。非常感谢您的帮助和指导! 以下是我在Windows Phone客户端上的代码: // Wi
// Windows Phone Client code (MainPage.xaml.cs)
// This function is called when an image is selected from
// the task PhotoChooserTask ptask, which brings
// a popup that allows the user to choose an image
// from the phone's storage
void ptask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null)
{
//Take JPEG stream and decode into a WriteableBitmap object
App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
// Attempt to send the image
WriteableBitmap pic = new WriteableBitmap(App.CapturedImage);
MemoryStream stream = new MemoryStream();
pic.SaveJpeg(stream, App.CapturedImage.PixelHeight, App.CapturedImage.PixelWidth, 0, 100);
stream.Seek(0, SeekOrigin.Begin);
client.Send(stream);
// Close the socket connection explicitly
client.Close();
}
}
下面是SocketClient.cs中的代码
public string Send(MemoryStream data)
{
byte[] msData = data.ToArray();
if (_socket != null)
{
// Create SocketAsyncEventArgs context object
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
// Set properties on context object
socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
socketEventArg.UserToken = null;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
{
_clientDone.Set();
});
// Add the data to be sent into the buffer
socketEventArg.SetBuffer(msData, 0, msData.Length);
// Sets the state of the event to nonsignaled, causing threads to block
_clientDone.Reset();
// Make an asynchronous Send request over the socket
_socket.SendAsync(socketEventArg);
}
else
{
response = "Socket is not initialized";
}
return response;
}
输出图像与从windows phone发送的图像相同,只是没有任何Exif信息。任何人都可以指出我做错了什么导致信息丢失?我猜是因为我在windows phone代码中调用了SaveJpeg函数,重写了图像文件,并丢失了其中的所有信息,但我不知道如何将图像转换为字节并流式传输
非常感谢您的帮助!谢谢。我找到了自己问题的答案。对于那些可能对此有问题的人。我只是使用:
Byte[] imageData = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Position = 0;
e.ChosenPhoto.Read(imageData, 0, imageData.Length);
然后在我的发送函数中发送字节数组:
socketEventArg.SetBuffer(imageData, 0, imageData.Length);
它可能有助于将您的代码简化为一个更小、更简单的测试用例来演示您的问题。@RichardPena所以我创建了一个可写的位图,将其转换为MemoryStream,然后转换为字节数组。Jave服务器接收字节数组并将其写入文件。图像在那里,但我丢失了Exif信息。这是我的问题。@RichardPena在这些步骤中,我可能做了一些不必要的事情。所以请随意评论!
socketEventArg.SetBuffer(imageData, 0, imageData.Length);