/// <summary> /// 发送图片 /// </summary> /// <param name="fileName"></param> private void sendPicture(string fileName) { if (string.IsNullOrEmpty(fileName)) { return; } var ext = fileName.Substring(fileName.LastIndexOf('.') + 1); var message = new NIMImageMessage { SessionType = NIMSessionType.kNIMSessionTypeP2P, ReceiverID = target.accid, ImageAttachment = new NIMImageAttachment { DisplayName = fileName, FileExtension = ext }, LocalFilePath = fileName, }; var body = new FileMessage { image = Util.getImageFromFile(fileName) }; message.ImageAttachment.Height = body.image.Height; message.ImageAttachment.Width = body.image.Width; sendMessage(1, body); TalkAPI.SendMessage(message); }
void SendFile(string path) { string fileName = System.IO.Path.GetFileNameWithoutExtension(path); string extension = System.IO.Path.GetExtension(path); if (IsImageFile(path)) { NIM.NIMImageMessage imageMsg = new NIMImageMessage(); imageMsg.LocalFilePath = path; imageMsg.ImageAttachment = new NIMImageAttachment(); imageMsg.ImageAttachment.DisplayName = fileName; imageMsg.ImageAttachment.FileExtension = extension; imageMsg.ReceiverID = _peerId; imageMsg.SessionType = _sessionType; using (var i = Image.FromFile(path)) { imageMsg.ImageAttachment.Height = i.Height; imageMsg.ImageAttachment.Width = i.Width; } TalkAPI.SendMessage(imageMsg); } else { NIM.NIMFileMessage fileMsg = new NIMFileMessage(); fileMsg.LocalFilePath = path; fileMsg.FileAttachment = new NIMMessageAttachment(); fileMsg.FileAttachment.DisplayName = fileName; fileMsg.FileAttachment.FileExtension = extension; fileMsg.ReceiverID = _peerId; fileMsg.SessionType = _sessionType; NIM.TalkAPI.SendMessage(fileMsg, (uploaded, total, obj) => { OutputForm.Instance.SetOutput(string.Format("upload file:{0} {1}/{2}", path, uploaded, total)); }); } }