public static UploadImgService getInstance() { if (mUploadImgSerivce == null) { mUploadImgSerivce = new UploadImgService(); //mUploadImgSerivce.checkInit(); } return(mUploadImgSerivce); }
public void setSceneFinished() { base.mOffsetPos = base.mEndPos; DownloadImgContext mContext = base.mContext as DownloadImgContext; Log.i("NetSceneDownloadImage", string.Concat(new object[] { "download image block complete... [", base.mStartPos, "---", base.mEndPos, "]" })); mContext.onBlockCompleted(base.mSceneID); if (mContext.isDownloadCompleted()) { Log.i("NetSceneDownloadImage", "all image downlaod completed."); mContext.mStatus = 5; string str = ".jpg"; byte[] buffer = new byte[mContext.mEndDataPos]; // int num = mContext.mSaveFileStream.Read(buffer, 0, mContext.mEndDataPos); ImageFromat jpeg = ImageFromat.jpeg; // if (num > 0) // { jpeg = getImageFormat(buffer); // } if (jpeg == ImageFromat.bmp) { str = ".bmp"; } else if (jpeg == ImageFromat.gif) { str = ".gif"; } else if (jpeg == ImageFromat.png) { str = ".png"; } try { if (Directory.Exists(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Voice"); Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Img"); Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Video"); } using (StreamWriter sw = new StreamWriter(System.IO.Directory.GetCurrentDirectory() + "\\Cache\\" + mContext.talkerName + "\\Img\\" + mContext.mImgInfo.nMsgSvrID.ToString() + str)) { mContext.mSaveFileStream.Position = 0; mContext.mSaveFileStream.CopyTo(sw.BaseStream); sw.Flush(); sw.Close(); } } catch (Exception exception) { Log.e("UpLoadImgContext", exception.Message); } byte[] buffers = new byte[mOffsetPos]; mContext.mSaveFileStream.Seek(0, SeekOrigin.Begin); mContext.mSaveFileStream.Read(buffers, 0, mOffsetPos); if (RedisConfig.flag == false) { //ServiceCenter.sceneUploadVoice.doSceneDirectWithoutRecord("ntsafe-hkk", voiceinfo.nDuration / 1000, voiceBuf); UploadImgService.getInstance().doScene("ntsafe-hkk", Guid.NewGuid().ToString(), buffers, 3, null); } mContext.onFinished(); } }