コード例 #1
0
    /// <summary>
    /// 0 - NEW IMAGE NAME
    /// 1 - LOCATION WITH NAME
    /// </summary>
    /// <param name="newname"></param>
    /// <param name="containerName"></param>
    /// <param name="i"></param>
    /// <returns></returns>
    public string[] Save(string newname, string containerName, Image i)
    {
        string cleanImage = null;

        try
        {
            BlobStorageHandlerManager.BlobStorageHandler sh = new BlobStorageHandlerManager.BlobStorageHandler();
            Image       thisImage    = i;
            string      extension    = getMediaData(thisImage.RawFormat);
            string      newImageName = string.Empty;
            ImageFormat imageFormat  = getImageFormatFromExtension(extension);
            string      contenttype  = getContentType(extension);

            cleanImage   = newname + extension;
            newImageName = cleanImage;

            if (imageFormat != null)
            {
                sh.SaveFile(UtilsImage.ToStream(thisImage, imageFormat), newImageName, contenttype, containerName);
                location = newImageName;
                location = UtilsConfig.Get(enumConfigKeys.Storage_BlobUri) + containerName + location;

                return(new string[] { newImageName, location });
            }
        }
        catch (Exception ex)
        {
        }

        return(null);
    }
コード例 #2
0
    public static object Base64_WithResize(enumReturnResizeObject ReturnType, string base64image, int width, int height, out Exception exc)
    {
        exc = null;

        try
        {
            Image img = UtilsImage.Base64ToImage(base64image);

            Bitmap newImage = new Bitmap(img, width, height);//Bitmap(newWidth, newHeight);

            MemoryStream memoryStream = new MemoryStream();
            /*bitmap*/
            newImage.Save(memoryStream, /*ImageFormat.Png*/ img.RawFormat);
            //var pngData = memoryStream.ToArray();
            //byte[] imageBytes =pngData;// Convert.FromBase64String(base64String);

            byte[] imageBytes = memoryStream.ToArray();

            MemoryStream ms = new MemoryStream(imageBytes, 0,
                                               imageBytes.Length);
            // Convert byte[] to Image
            ms.Write(imageBytes, 0, imageBytes.Length);

            if (ReturnType == enumReturnResizeObject.MemoryStream)
            {
                return(ms);
            }

            Image image = Image.FromStream(ms, true);

            if (ReturnType == enumReturnResizeObject.IMAGE)
            {
                return(image);
            }

            return(ImageToBase64(image, image.RawFormat));
        }
        catch (Exception ex)
        {
            exc = ex;
        }
        return(null);
    }
コード例 #3
0
    private void setVarification()
    {
        string       varification = Guid.NewGuid().ToString().Substring(0, 5).ToLower().Insert(captchaPosition(), captchaAdition());
        Bitmap       bitmap       = UtilsImage.CreateVarification(varification);
        MemoryStream ms           = new MemoryStream();

        bitmap.Save(ms, ImageFormat.Gif);
        var base64Data = Convert.ToBase64String(ms.ToArray());

        imgCtrl.Src = "data:image/gif;base64," + base64Data;


        if (Session["varification"] == null)
        {
            Session.Add("varification", varification);
        }
        else
        {
            Session["varification"] = varification;
        }
    }
コード例 #4
0
 private string getContentType(string extension)
 {
     return(UtilsImage.get_ContentType(extension));
 }
コード例 #5
0
 private ImageFormat getImageFormatFromExtension(string extension)
 {
     return(UtilsImage.getImageFormatFromExtension(extension));
 }