Click here to Skip to main content
15,906,708 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Developing an election ballot box app. Pin
samflex22-Apr-16 6:23
samflex22-Apr-16 6:23 
QuestionRe: Developing an election ballot box app. Pin
ZurdoDev22-Apr-16 6:32
professionalZurdoDev22-Apr-16 6:32 
AnswerRe: Developing an election ballot box app. Pin
F-ES Sitecore24-Apr-16 3:01
professionalF-ES Sitecore24-Apr-16 3:01 
GeneralRe: Developing an election ballot box app. Pin
samflex24-Apr-16 13:21
samflex24-Apr-16 13:21 
GeneralRe: Developing an election ballot box app. Pin
F-ES Sitecore24-Apr-16 22:51
professionalF-ES Sitecore24-Apr-16 22:51 
GeneralRe: Developing an election ballot box app. Pin
samflex25-Apr-16 4:38
samflex25-Apr-16 4:38 
GeneralRe: Developing an election ballot box app. Pin
F-ES Sitecore25-Apr-16 4:49
professionalF-ES Sitecore25-Apr-16 4:49 
GeneralRe: Developing an election ballot box app. Pin
samflex25-Apr-16 5:49
samflex25-Apr-16 5:49 
GeneralRe: Developing an election ballot box app. Pin
F-ES Sitecore25-Apr-16 23:11
professionalF-ES Sitecore25-Apr-16 23:11 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming26-Apr-16 1:42
mveRichard Deeming26-Apr-16 1:42 
GeneralRe: Developing an election ballot box app. Pin
samflex26-Apr-16 5:59
samflex26-Apr-16 5:59 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming26-Apr-16 7:28
mveRichard Deeming26-Apr-16 7:28 
GeneralRe: Developing an election ballot box app. Pin
samflex28-Apr-16 8:04
samflex28-Apr-16 8:04 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming28-Apr-16 8:08
mveRichard Deeming28-Apr-16 8:08 
GeneralRe: Developing an election ballot box app. Pin
samflex28-Apr-16 9:59
samflex28-Apr-16 9:59 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming28-Apr-16 11:03
mveRichard Deeming28-Apr-16 11:03 
GeneralRe: Developing an election ballot box app. Pin
samflex28-Apr-16 11:58
samflex28-Apr-16 11:58 
GeneralRe: Developing an election ballot box app. Pin
Richard Deeming29-Apr-16 2:04
mveRichard Deeming29-Apr-16 2:04 
GeneralRe: Developing an election ballot box app (SOLVED). Pin
samflex2-May-16 3:22
samflex2-May-16 3:22 
QuestionUpdate progressbar with wcf webservice Pin
Member 1247474222-Apr-16 1:05
Member 1247474222-Apr-16 1:05 
SuggestionRe: Update progressbar with wcf webservice Pin
Richard Deeming22-Apr-16 1:15
mveRichard Deeming22-Apr-16 1:15 
Questionpls Help me..binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city.. Pin
sunil321-Apr-16 0:28
sunil321-Apr-16 0:28 
AnswerRe: pls Help me..binding dropdown like Country,State,City..when im selecting any one country it showing me all country's state and city.. Pin
John C Rayan21-Apr-16 0:55
professionalJohn C Rayan21-Apr-16 0:55 
Questionc# Image Processing from byte[] to image, centering the image on a square canvas Pin
jkirkerx20-Apr-16 13:47
professionaljkirkerx20-Apr-16 13:47 
This is for my new program written in MVC, in which I'm using lots avatars to represent things like users and items.

In my old program code in VB, I picked up the image from the disk drive, make a new canvas and wrote the image on the new canvas centering it back to the drive.

In this program, I got slick and took the bytes[] from file upload, and then I feed them into this function that returns the image back to me in various formats such as bytes[]. The program works, but I just can't get the new resized image to center on the canvas, it always starts on the left edge. The height is correct, but I get a black strip on the right side because it's smaller.

I'm not looking for someone to write code for me, just take a look at the function and perhaps you can see where I blew it and made a mistake. Perhaps its the order of graphic objects, maybe I have it backwards.
C#
<pre lang="text">    Your codeblocks should be of the form

    ```C#
/// avatar_resize
/// resizes an image that is a byte[] and return an image model
/// 
/// <param name="pName">Name of the Image</param>
/// <param name="pBytes">Byte Array of the image uploaded to the server</param>
/// <returns>model_image_object, with new resized byte array</returns>
public static model_image_object avatar_resize(string pName, byte[] pBytes)
{
    // Target Width / Height
    // Make a square image
    const int t_Width = 250;
    const int t_Height = 250;
    int cHeight = 0;
    int cWidth = 0;

    // Create the return Image Object
    model_image_object pResult = new model_image_object();
    MemoryStream stream_out = new MemoryStream();
    using (Stream stream_in = new MemoryStream(pBytes))
    {
        // Create an Image so we can get the image parameters
        Image image_in = Image.FromStream(stream_in);

        // Write this to the drive and visually inspect it, is it correct?
        //image_in.Save(System.Web.HttpContext.Current.Server.MapPath("~/Images/smtp/image_in.png"));

        // Figure out what we need to do to resize this image
        int oWidth = image_in.Width;
        int oHeight = image_in.Height;
        Color bgColor = Color.FromArgb(255, 255, 255);

        // Create the canvas for the new resized image
        using (Bitmap bitmapObj = new Bitmap(t_Width, t_Height, PixelFormat.Format24bppRgb))
        {
            // Create the new graphics, that will overlay the Bitmap Canvas
            using (Graphics graphicObj = Graphics.FromImage(bitmapObj))
            {
                graphicObj.Clear(Color.Transparent);
                graphicObj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
                graphicObj.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

                // Calculate the new Height and Width of the Image
                if (oWidth == oHeight)
                {
                    cWidth = 250;
                    cHeight = 250;
                }
                else if (oWidth > t_Width)
                {
                    cWidth = t_Width;
                    cHeight = (int)Math.Round((oHeight / (float)oWidth) * t_Width);
                }
                else if (oWidth < t_Width)
                {
                    cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
                    cHeight = (int)Math.Round((oHeight / (float)oWidth) * cWidth);    

                }
                else if (oHeight > t_Height)
                {
                    cHeight = t_Height;
                    cWidth = (int)Math.Round((oWidth / (float)oHeight) * t_Height);
                }

                // Calculate how to overlay the width of the image centered                        
                int x = (cWidth - t_Width) / 2;
                int y = (cHeight - t_Height) / 2;    

                // Create the new Image Object
                graphicObj.DrawImage(image_in, x, y, t_Width, t_Height);

                // Save the Graphic Object
                graphicObj.Save();
            }

            // Now write the image_out to test it and make sure it's correct, right size and placement            
            //bitmapObj.Save(System.Web.HttpContext.Current.Server.MapPath("~/Images/avatars/products/bitmap_out.png"));

            // Create a new MemoryStream to Save the Image to
            bitmapObj.Save(stream_out, ImageFormat.Png);
        }
    }

    // Program the pResult
    pResult.Data = stream_out.ToArray();
    pResult.Name = pName;
    pResult.Type = "image/png";
    pResult.Size = new model_image_type_size();
    pResult.Size.Height = cHeight;
    pResult.Size.Width = cWidth;

    return pResult;
}
    ```


public class model_image_object
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public byte[] Data { get; set; }
        public model_image_type_size Size { get; set; }
    }

AnswerRe: c# Image Processing from byte[] to image, centering the image on a square canvas Pin
Richard Deeming21-Apr-16 2:40
mveRichard Deeming21-Apr-16 2:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.