Click here to Skip to main content
15,911,306 members
Home / Discussions / C#
   

C#

 
GeneralRe: Check who has taken the handle of the text file. [modified] Pin
Sunil G22-Feb-10 21:19
Sunil G22-Feb-10 21:19 
GeneralRe: Check who has taken the handle of the text file. Pin
Calla22-Feb-10 21:37
Calla22-Feb-10 21:37 
GeneralRe: Check who has taken the handle of the text file. [modified] Pin
Sunil G22-Feb-10 21:40
Sunil G22-Feb-10 21:40 
GeneralRe: Check who has taken the handle of the text file. Pin
Calla22-Feb-10 22:14
Calla22-Feb-10 22:14 
GeneralRe: Check who has taken the handle of the text file. Pin
Manoj_Leo23-Feb-10 6:42
Manoj_Leo23-Feb-10 6:42 
AnswerRe: Check who has taken the handle of the text file. Pin
Saksida Bojan23-Feb-10 1:31
Saksida Bojan23-Feb-10 1:31 
GeneralRe: Check who has taken the handle of the text file. Pin
Sunil G23-Feb-10 2:29
Sunil G23-Feb-10 2:29 
QuestionImage Interpolation Pin
Steven Schmoll22-Feb-10 18:40
Steven Schmoll22-Feb-10 18:40 
Hi I've been working on making a quadrilateral image distortion algorithm and I have managed to make it distort any image into the shape specified but I cant manage to work out how to apply even bilinear interpolation. I would like some help if anyone can, to add interpolation to my algorithm. I have included the distortion code below:

private Bitmap DistortImage(Image sourceImage,Point TopLeft, Point TopRight, Point BottomLeft, Point BottomRight)
{
    int width, height; //The destination bitmap size

    width = Convert.ToInt32(Math.Max(p2.X, p4.X));
    height = Convert.ToInt32(Math.Max(p3.Y, p4.Y));

    Bitmap dest = new Bitmap(width, height);
    Bitmap src = new Bitmap(sourceImage);

    //Start the loop

    //Loop down the left border
    for (int yStart = TopLeft.Y; yStart < BottomLeft.Y; yStart++)
    {
        //Find where the left most part is
        double xStart = TopLeft.X + (((double)(yStart - TopLeft.Y) / (double)(BottomLeft.Y - TopLeft.Y) * (BottomLeft.X - TopLeft.X)));
        //Find the x and y position corrisponding on the right border
        double yEnd = TopRight.Y + ((double)(yStart - TopLeft.Y) / (double)(BottomLeft.Y - TopLeft.Y)) * (BottomRight.Y - TopRight.Y);
        double xEnd = TopRight.X + (((double)(yEnd - TopRight.Y) / (double)(BottomRight.Y - TopRight.Y) * (BottomRight.X - TopRight.X)));

        //How stretched this line is
        double xScale = (xEnd - xStart) / (double)src.Width;

        //Loop through the line and draw according to it
        for (double x = xStart; x < xEnd; x+= xScale)
        {
            double y = yStart + (((double)(x - xStart) / (double)(xEnd - xStart) * (yEnd - yStart)));
            //How stretched the line is vertically
            double yScale =   ((double)(x - xStart) / (double)(xEnd - xStart)) / ((double)(BottomLeft.Y - TopLeft.Y) / (double)(BottomRight.Y - TopRight.Y));

            //Find out what src pixel this will use
            double ySrc = ((double)(yStart - TopLeft.Y) / (double)(BottomLeft.Y - TopLeft.Y)) * src.Height;
            double xSrc = ((double)(x - xStart) / (double)(xEnd - xStart)) * src.Width;

            //Find out how many pixels we are responsible for drawing
            int xNumPixels, yNumPixels;
            xNumPixels = Convert.ToInt32(Math.Ceiling(xScale));
            yNumPixels = Convert.ToInt32(Math.Ceiling(yScale));

            int yNumPixelsAbove;
            yNumPixelsAbove = Convert.ToInt32(Math.Ceiling(yNumPixels / 2d));

            if (xSrc < 0)
                xSrc = 0;
            if (ySrc < 0)
                ySrc = 0;

            //The source pixel
            Color col = src.GetPixel(Convert.ToInt32(Math.Floor(xSrc)), Convert.ToInt32(Math.Floor(ySrc)));

            //Draw all the pixels needed
            for (int sx = Convert.ToInt32(Math.Floor(x)); sx < Convert.ToInt32(Math.Floor(x)) + xNumPixels; sx++)
            {
                if (sx < width)
                {
                    for (int sy = Convert.ToInt32(Math.Floor(y)) - yNumPixelsAbove; sy < Convert.ToInt32(Math.Floor(y)) + yNumPixels; sy++)
                    {
                        if (sy >= 0 && sy < height)
                            dest.SetPixel(sx, sy, col);
                    }
                }
            }
        }
    }

    src.Dispose();
    src = null;

    return dest;
}


Thanks in advance to anyone who can help
"I'm very good at multitasking. I can completely ignore you and do this at the same time"

AnswerRe: Image Interpolation Pin
RichardM123-Feb-10 14:50
RichardM123-Feb-10 14:50 
GeneralRe: Image Interpolation Pin
Steven Schmoll23-Feb-10 16:43
Steven Schmoll23-Feb-10 16:43 
QuestionWarning Message box Pin
shahramkeyboard22-Feb-10 8:48
shahramkeyboard22-Feb-10 8:48 
AnswerRe: Warning Message box Pin
Not Active22-Feb-10 11:54
mentorNot Active22-Feb-10 11:54 
QuestionC# .net.Mail Pin
Jamelon6922-Feb-10 8:19
Jamelon6922-Feb-10 8:19 
AnswerRe: C# .net.Mail Pin
DaveyM6922-Feb-10 8:29
professionalDaveyM6922-Feb-10 8:29 
AnswerRe: C# .net.Mail Pin
Dr.Walt Fair, PE22-Feb-10 8:31
professionalDr.Walt Fair, PE22-Feb-10 8:31 
AnswerRe: C# .net.Mail Pin
Gaurav Dudeja India22-Feb-10 19:20
Gaurav Dudeja India22-Feb-10 19:20 
AnswerRe: C# .net.Mail Pin
Richard MacCutchan22-Feb-10 22:16
mveRichard MacCutchan22-Feb-10 22:16 
QuestionBest way to read ASCII input [modified] Pin
spainchaud22-Feb-10 6:13
spainchaud22-Feb-10 6:13 
AnswerRe: Best way to read ASCII input Pin
harold aptroot22-Feb-10 6:32
harold aptroot22-Feb-10 6:32 
GeneralRe: Best way to read ASCII input Pin
spainchaud22-Feb-10 6:38
spainchaud22-Feb-10 6:38 
AnswerRe: Best way to read ASCII input [modified] Pin
Saksida Bojan22-Feb-10 6:36
Saksida Bojan22-Feb-10 6:36 
GeneralRe: Best way to read ASCII input Pin
harold aptroot22-Feb-10 6:39
harold aptroot22-Feb-10 6:39 
AnswerRe: Best way to read ASCII input Pin
Dr.Walt Fair, PE22-Feb-10 7:03
professionalDr.Walt Fair, PE22-Feb-10 7:03 
GeneralRe: Best way to read ASCII input Pin
spainchaud22-Feb-10 8:48
spainchaud22-Feb-10 8:48 
GeneralRe: Best way to read ASCII input Pin
Dr.Walt Fair, PE22-Feb-10 9:23
professionalDr.Walt Fair, PE22-Feb-10 9:23 

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.