80,472
社区成员




public Byte[] getphoto(string photopath)
{
string str = photopath;
FileStream file = new FileStream(str, FileMode.Open, FileAccess.Read);
Byte[] bytBLOBData = new Byte[file.Length];
file.Read(bytBLOBData, 0, bytBLOBData.Length);
file.Close();
return bytBLOBData;
}
private void SendData(string data)
{
try
{
Byte[] msg = getphoto(data);
userList[0].socket.Send(msg, msg.Length, SocketFlags.None);
MessageBox.Show("" + msg.Length);
data = string.Format("To[{0}]:{1}", userList[0].socket.RemoteEndPoint.ToString(), data);
listBoxStatu.Invoke(AppendString, data);
}
catch
{
}
}
private class ReceiveThread extends Thread {
private BufferedInputStream dis = null;
private Socket s = null;
ReceiveThread(Socket socket) {
try {
s = socket;
dis = new BufferedInputStream(s.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void run() {
while (isConnect) {
try {
Thread.sleep(1000);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[ 1024];
int len = -1;
while ((len = dis.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
byte[] data = outStream.toByteArray();
outStream.flush();
outStream.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inSampleSize = 10; // width,hight设为原来的十分一
if (data.length > 0) {
bm = BitmapFactory.decodeByteArray(data, 0,
data.length, options);
if (bm != null) {
System.out.println(data.length);
myHandler.sendEmptyMessage(0);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
close();
}
}
}
}