示例#1
0
        public string UploadImageStream(Stream stream)
        {
            var uriPath = "/test/" + UpYun.random_string() + ".jpg";

            Hashtable headers = new Hashtable();

            BinaryReader r         = new BinaryReader(stream);
            var          postArray = r.ReadBytes((int)stream.Length);

            stream.Seek(0, SeekOrigin.Begin);
            this.setContentMD5(UpYun.md5_stream(stream));

            Console.WriteLine("upload " + uriPath);

            return(this.writeFile(uriPath, postArray, true) ? "http://wxhowoldtest.b0.upaiyun.com" + uriPath : null);
        }
示例#2
0
        private string RenderAnalysisResultAsImage(AnalysisResult result, string captionText, string commentText)
        {
            timeLogger.Append(string.Format("{0} VisionHelper::AnalyzeImage::RenderAnalysisResultAsImage begin\n", DateTime.Now - this.startTime));
            string resultUrl = null;

            var upyun = new UpYun("wxhowoldtest", "work01", "vYiJVc7iYY33w58O");

            //using (var midStream = new MemoryStream(photoBytes))
            //{
            midStream = new MemoryStream(photoBytes);
            var outStream = new MemoryStream();

            timeLogger.Append(string.Format("{0} VisionHelper::AnalyzeImage::RenderAnalysisResultAsImage imageFactory.Load begin\n", DateTime.Now - this.startTime));

            midStream.Seek(0, SeekOrigin.Begin);
            midStream = DrawText(captionText, result.Metadata.Width, 5, result.Color);
            midStream.Seek(0, SeekOrigin.Begin);

            midStream = DrawRects(midStream, result);
            midStream.Seek(0, SeekOrigin.Begin);

            //var len = commentText.Length;
            //midStream = DrawText(commentText.Substring(0, len / 4), result.Metadata.Width, 0, result.Color);
            //midStream.Seek(0, SeekOrigin.Begin);
            //midStream = DrawText(commentText.Substring(len / 4, len / 4), result.Metadata.Width, 1, result.Color);
            //midStream.Seek(0, SeekOrigin.Begin);
            //midStream = DrawText(commentText.Substring(2 * (len / 4), len / 4), result.Metadata.Width, 2, result.Color);
            //midStream.Seek(0, SeekOrigin.Begin);
            //midStream = DrawText(commentText.Substring(3 * (len / 4)), result.Metadata.Width, 3, result.Color);
            //midStream.Seek(0, SeekOrigin.Begin);

            //outStream.Seek(0, SeekOrigin.Begin);

            //var midStream =
            timeLogger.Append(string.Format("{0} VisionHelper::AnalyzeImage::RenderAnalysisResultAsImage imageFactory.Load midStream generated\n", DateTime.Now - this.startTime));


            //outStream.Seek(0, SeekOrigin.Begin);
            //outStream = tulisnamafile2(midStream, captionText);
            timeLogger.Append(string.Format("{0} VisionHelper::AnalyzeImage::RenderAnalysisResultAsImage Upload to image CDN begin\n", DateTime.Now - this.startTime));

            //   return string.Format("酷评:\n{0}\n归图:\n{1}", captionText, resultUrl);


            // Retrieve reference to a blob named "myblob".
            //string blobName = string.Format("{0}_{1}.jpg", this.curUserName, random_string(12));
            int idx = this.curUserName.LastIndexOf('_');

            idx = idx > -1? idx : 0;
            string         blobName  = string.Format("{0}/{1}.jpg", this.curUserName.Substring(idx), random_string(13));
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);

            // Create or overwrite the "myblob" blob with contents from a local file.
            //midStream.Seek(0, SeekOrigin.Begin);
            //blockBlob.UploadFromStream(midStream);
            midStream.Seek(0, SeekOrigin.Begin);
            blockBlob.UploadFromStream(midStream);
            resultUrl = "http://howhot.blob.core.windows.net/cdn/" + blobName;
            //resultUrl = "http://geeekstore.blob.core.windows.net/cdn/" + blobName;
            //resultUrl = upyun.UploadImageStream(outStream);

            this.returnImageUrl = resultUrl;
            timeLogger.Append(string.Format("{0} VisionHelper::AnalyzeImage::RenderAnalysisResultAsImage Upload to image CDN end\n", DateTime.Now - this.startTime));
            //}


            //return string.Format("画说:\n{0}", resultUrl);
            //return string.Format("谈画:\n{0}\n归图:\n{1}\n", noAdsTxtResult, resultUrl);
            //return string.Format("谈画:\n{0}\n想知道您上传的图片有多\"Hot\"么? 请看归图:\n{1}\n", commentText, resultUrl);
            return(string.Format("谈画:\n{0}", commentText));
            //return string.Format("画说:\n{0}\n归图:\n{1}\n原图:\n{2}", captionText, resultUrl, this.originalImageUrl);
        }