Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
GeneralRe: Form controls data binding sequence Pin
Xpnctoc24-May-10 8:15
Xpnctoc24-May-10 8:15 
QuestionVisual Studions 2005 and crystal reports 11.5 R2 Pin
krown24-May-10 2:56
krown24-May-10 2:56 
QuestionWhy am I recieving corrupt images? Pin
TimSWatson24-May-10 2:37
TimSWatson24-May-10 2:37 
AnswerRe: Why am I recieving corrupt images? Pin
Luc Pattyn24-May-10 4:53
sitebuilderLuc Pattyn24-May-10 4:53 
JokeRe: Why am I recieving corrupt images? Pin
Wes Aday24-May-10 8:27
professionalWes Aday24-May-10 8:27 
JokeRe: Why am I recieving corrupt images? Pin
DaveyM6924-May-10 9:06
professionalDaveyM6924-May-10 9:06 
GeneralRe: Why am I recieving corrupt images? Pin
TimSWatson25-May-10 4:42
TimSWatson25-May-10 4:42 
Questiontext alignment problem on the image.... Pin
Nivas8224-May-10 1:40
Nivas8224-May-10 1:40 
Hi,

I have the picture box in which i draw the rectangle (using graphics paint) and inside that rectangle I typed some name using label box and stored the work, have done.(for this please ref: http://www.codeproject.com/Messages/3474995/How-can-save-picturebox-image-using-menustrip.aspx[])

When I opened the saved Image the position of text I typed in the label box not in the position where I try to place (on screen). It's saving the text in some other position.

How to co-ordinate the resolution using c#.
Image bac;
Bitmap myBitmap;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
            if (mybitmap == null)
            {
                mybitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());

            }
               
            rect = new Rectangle(e.X, e.Y, 0, 0);
             this.Invalidate();
                
}


private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{

             
               switch (e.Button)
      {
                case MouseButtons.Left:
           {
                    rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
                    this.Invalidate();
         
                break;
            }

       }
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{

            if (mybitmap == null)
            {
                return;
            }
            using (Pen pen = new Pen(Color.Red, 2))
            {
                using (Graphics g = Graphics.FromImage(mybitmap))
                {
                e.Graphics.DrawRectangle(pen, rect);
                    
                 if (label1.TextAlign == ContentAlignment.TopLeft)
                    {
                        e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Bounds); 
                        g.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Bounds);
mybitmap.PixelFormat);
                    }
                    else if (label1.TextAlign == ContentAlignment.TopCenter)
                    {
                        SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
                        float left = ((float)this.Width + label1.Left) / 2 - size.Width / 2;
                        RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
                        e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);

                    }
                    else
                    {
                        SizeF size = e.Graphics.MeasureString(label1.Text, label1.Font);
                        float left = (float)label1.Width - size.Width + label1.Left;
                        RectangleF rect1 = new RectangleF(left, (float)label1.Top, size.Width, label1.Height);
                        e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), rect1);
                    }

               }

        }
            
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{


            if (mybitmap != null)
            {
                SaveFileDialog SaveFD1 = new SaveFileDialog();
                SaveFD1.FileName = "";
                SaveFD1.InitialDirectory = "C";
                SaveFD1.Title = "save file Name";
                SaveFD1.Filter = "JPG|*.jpg|Bmp|*.bmp";
                 if (SaveFD1.ShowDialog() == DialogResult.OK)
                {
                    
                    System.IO.Stream filename = (System.IO.FileStream)SaveFD1.OpenFile();

                    int r = SaveFD1.FileName.Length;
                    for (int r1 = 0; r1<=r;)
                    {
                        if (SaveFD1.FileName[r1] != '.')
                            r1++;
                        else
                        {
                            r = r1;
                            break;
                        }
                    }
                    
                       if (SaveFD1.FileName[++r] == 'j')
                        {
                            using (Graphics g = Graphics.FromImage(bac))
                        {
                           g.DrawImage(mybitmap, 0, 0);
                        }
                        bac.Save(filename, ImageFormat.Jpeg);
                        }
                        else if (SaveFD1.FileName[r] == 'b')
                        {
                            using (Graphics g = Graphics.FromImage(bac))
                            {
                                g.DrawImage(mybitmap, 0, 0);
                            }
                            bac.Save(filename, ImageFormat.Jpeg);
                        }
                        else
                        {
                            using (Graphics g = Graphics.FromImage(bac))
                            {
                                g.DrawImage(mybitmap, 0, 0);
                            }
                            bac.Save(filename, ImageFormat.Png);
                        }
                    
                    filename.Close();

                }
            }
        }

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{

            OpenFD.FileName = "";
            OpenFD.Title = "open image";
            OpenFD.InitialDirectory = "C";
            OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*";
            if (OpenFD.ShowDialog() == DialogResult.OK)
            {
                file = OpenFD.FileName;
                
                bac = Image.FromFile(file);
                pictureBox1.Image = bac;
                pictureBox1.Invalidate();
                

            }

        }

AnswerRe: text alignment problem on the image.... Pin
Luc Pattyn24-May-10 4:43
sitebuilderLuc Pattyn24-May-10 4:43 
GeneralRe: text alignment problem on the image.... Pin
Nivas8226-May-10 22:04
Nivas8226-May-10 22:04 
GeneralRe: text alignment problem on the image.... Pin
Luc Pattyn27-May-10 3:10
sitebuilderLuc Pattyn27-May-10 3:10 
AnswerRe: text alignment problem on the image.... [modified] Pin
Nivas8228-May-10 19:31
Nivas8228-May-10 19:31 
AnswerRe: text alignment problem on the image.... Pin
Nivas8230-May-10 22:37
Nivas8230-May-10 22:37 
QuestionUnable to figure out a proper subject line. Sorry. :( Pin
dashingsidds23-May-10 23:41
dashingsidds23-May-10 23:41 
AnswerRe: Unable to figure out a proper subject line. Sorry. :( Pin
Richard MacCutchan23-May-10 23:51
mveRichard MacCutchan23-May-10 23:51 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
dashingsidds24-May-10 0:40
dashingsidds24-May-10 0:40 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
Richard MacCutchan24-May-10 1:26
mveRichard MacCutchan24-May-10 1:26 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
PIEBALDconsult24-May-10 4:32
mvePIEBALDconsult24-May-10 4:32 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
dashingsidds24-May-10 18:43
dashingsidds24-May-10 18:43 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
PIEBALDconsult25-May-10 2:40
mvePIEBALDconsult25-May-10 2:40 
AnswerRe: Unable to figure out a proper subject line. Sorry. :( Pin
Pete O'Hanlon24-May-10 0:25
mvePete O'Hanlon24-May-10 0:25 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
dashingsidds24-May-10 0:43
dashingsidds24-May-10 0:43 
GeneralRe: Unable to figure out a proper subject line. Sorry. :( Pin
Pete O'Hanlon24-May-10 0:49
mvePete O'Hanlon24-May-10 0:49 
AnswerRe: Unable to figure out a proper subject line. Sorry. :( Pin
Łukasz Nowakowski24-May-10 0:51
Łukasz Nowakowski24-May-10 0:51 
AnswerRe: Unable to figure out a proper subject line. Sorry. :( Pin
Abhinav S24-May-10 1:40
Abhinav S24-May-10 1: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.