Click here to Skip to main content
15,917,652 members
Home / Discussions / C#
   

C#

 
AnswerRe: Generic Change Event handler Pin
DaveyM6919-Mar-09 5:40
professionalDaveyM6919-Mar-09 5:40 
GeneralRe: Generic Change Event handler Pin
dwolver19-Mar-09 6:02
dwolver19-Mar-09 6:02 
GeneralRe: Generic Change Event handler Pin
DaveyM6919-Mar-09 6:17
professionalDaveyM6919-Mar-09 6:17 
GeneralRe: Generic Change Event handler Pin
S. Senthil Kumar20-Mar-09 4:00
S. Senthil Kumar20-Mar-09 4:00 
AnswerRe: Generic Change Event handler Pin
dwolver19-Mar-09 6:17
dwolver19-Mar-09 6:17 
QuestionPrint multipage tiff images Pin
Deabdy2119-Mar-09 4:58
Deabdy2119-Mar-09 4:58 
GeneralRe: Print multipage tiff images Pin
Qwerty190621-Apr-10 3:21
Qwerty190621-Apr-10 3:21 
AnswerRe: Print multipage tiff images Pin
Deabdy2121-Apr-10 3:38
Deabdy2121-Apr-10 3:38 
No, but I've the answer.

With this metho I size the image to the wright size. You can put this method in a seperate class.

   <br />
public Image FixedSize(Image imgPhoto, int Width, int Height)<br />
    {<br />
      // met deze methode wordt een afbeelding gereside naar een exactie<br />
      // hoogte en breedte van een afbeelding<br />
      int sourceWidth = imgPhoto.Width;<br />
      int sourceHeight = imgPhoto.Height;<br />
      int sourceX = 0;<br />
      int sourceY = 0;<br />
      int destX = 0;<br />
      int destY = 0;<br />
<br />
      float nPercent = 0;<br />
      float nPercentW = 0;<br />
      float nPercentH = 0;<br />
<br />
      nPercentW = ((float)Width / (float)sourceWidth);<br />
      nPercentH = ((float)Height / (float)sourceHeight);<br />
<br />
    <br />
      if (nPercentH < nPercentW)<br />
      {<br />
        nPercent = nPercentH;<br />
        destX = (int)((Width - (sourceWidth * nPercent)) / 2);<br />
      }<br />
      else<br />
      {<br />
        nPercent = nPercentW;<br />
        destY = (int)((Height - (sourceHeight * nPercent)) / 2);<br />
      }<br />
<br />
      int destWidth = (int)(sourceWidth * nPercent);<br />
      int destHeight = (int)(sourceHeight * nPercent);<br />
<br />
      Bitmap bmPhoto = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);<br />
      bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);<br />
<br />
      Graphics grPhoto = Graphics.FromImage(bmPhoto);<br />
      grPhoto.Clear(Color.White);<br />
      grPhoto.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;<br />
      grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;<br />
      grPhoto.SmoothingMode = SmoothingMode.AntiAlias;<br />
      grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;<br />
      grPhoto.CompositingQuality = CompositingQuality.HighQuality;<br />
<br />
      grPhoto.DrawImage(imgPhoto,<br />
        new Rectangle(destX, destY, destWidth, destHeight),<br />
        new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),<br />
        GraphicsUnit.Pixel);<br />
<br />
      grPhoto.Dispose();<br />
      return bmPhoto;<br />
    }



The next thing I did was to create class that derive from printdocument.
The next part of code:
    /// <summary><br />
    /// Prints an (multipage) image.<br />
    /// </summary><br />
    public class PrintImage : PrintDocument<br />
    {<br />
        /// <summary><br />
        /// The current page that is printed<br />
        /// </summary><br />
        private int currentPage;<br />
<br />
        /// <summary><br />
        /// The total number of pages.<br />
        /// </summary><br />
        private int numberOfPages;<br />
<br />
        /// <summary><br />
        /// The backing field for the image to print.<br />
        /// </summary><br />
        private Image imageToPrint;<br />
<br />
        /// <summary><br />
        /// Gets or sets the image to print. Must be set.<br />
        /// </summary><br />
        public Image ImageToPrint<br />
        {<br />
            get<br />
            {<br />
                return this.imageToPrint;<br />
            }<br />
<br />
            set<br />
            {<br />
                this.imageToPrint = value;<br />
                this.numberOfPages = this.imageToPrint.GetFrameCount(FrameDimension.Page);<br />
            }<br />
        }<br />
<br />
        /// <summary><br />
        /// Is called once when the printing starts. Initializes the currentpage.<br />
        /// </summary><br />
        /// <param name="e">PrintEventArgs from PrintDocument</param><br />
        protected override void OnBeginPrint(PrintEventArgs e)<br />
        {<br />
            base.OnBeginPrint(e);<br />
<br />
            this.currentPage = 0;<br />
<br />
            if (this.imageToPrint == null)<br />
            {<br />
                throw new ArgumentNullException("ImageToPrint");<br />
            }<br />
        }<br />
<br />
        /// <summary><br />
        /// Is called once for every page.<br />
        /// </summary><br />
        /// <param name="e">PrintEventArgs from PrintDocument</param><br />
        protected override void OnPrintPage(PrintPageEventArgs e)<br />
        {<br />
          AfbeeldingFormaat afb = new AfbeeldingFormaat();;<br />
            base.OnPrintPage(e);<br />
<br />
            // Select the current frame.<br />
            this.ImageToPrint.SelectActiveFrame(FrameDimension.Page, this.currentPage);<br />
<br />
            using (var bmp = new Bitmap(this.imageToPrint))<br />
            {<br />
              Image image;<br />
<br />
             image = afb.FixedSize(bmp, e.PageBounds.Width, e.PageBounds.Height);<br />
<br />
              e.Graphics.DrawImage(image, e.PageBounds);<br />
                // Draw the image scaled to the page bounds.<br />
              //  e.Graphics.DrawImage(bmp, e.PageBounds, bmp.GetBounds(ref gu), gu);<br />
<br />
                // Determine if there are more pages.<br />
                e.HasMorePages = ++this.currentPage < this.numberOfPages;<br />
            }<br />
        }<br />
    }


And then the last part to print.

<br />
      PrintDocument printDocument = new PrintImage { ImageToPrint = Image.FromFile(path) };<br />
<br />
      var ppd = new PrintDialog<br />
                  {<br />
                    Document = printDocument<br />
                  };<br />
<br />
      if (ppd.ShowDialog() == DialogResult.OK)<br />
      {<br />
<br />
        printDocument.Print();<br />
<br />
      }<br />
<br />


I hope this helps you.
GeneralRe: Print multipage tiff images Pin
reaperx905-Jul-11 3:57
reaperx905-Jul-11 3:57 
QuestionSave WebCam Capture with a resulution of 2MP Pin
nukebold19-Mar-09 4:55
nukebold19-Mar-09 4:55 
AnswerRe: Safe WebCam Capture with a resulution of 2MP Pin
musefan19-Mar-09 4:57
musefan19-Mar-09 4:57 
AnswerRe: Save WebCam Capture with a resulution of 2MP Pin
Dave Kreskowiak19-Mar-09 8:26
mveDave Kreskowiak19-Mar-09 8:26 
GeneralRe: Save WebCam Capture with a resulution of 2MP Pin
nukebold19-Mar-09 8:45
nukebold19-Mar-09 8:45 
GeneralRe: Save WebCam Capture with a resulution of 2MP Pin
Dave Kreskowiak19-Mar-09 11:01
mveDave Kreskowiak19-Mar-09 11:01 
Questionconvert class to dll Pin
sanforjackass19-Mar-09 4:42
sanforjackass19-Mar-09 4:42 
AnswerRe: convert class to dll Pin
DaveyM6919-Mar-09 4:44
professionalDaveyM6919-Mar-09 4:44 
GeneralRe: convert class to dll Pin
sanforjackass19-Mar-09 5:39
sanforjackass19-Mar-09 5:39 
AnswerRe: convert class to dll Pin
musefan19-Mar-09 4:44
musefan19-Mar-09 4:44 
AnswerRe: convert class to dll Pin
Cracked-Down19-Mar-09 5:29
Cracked-Down19-Mar-09 5:29 
QuestionSend an email witch c# Pin
abbd19-Mar-09 4:32
abbd19-Mar-09 4:32 
AnswerRe: Send an email witch c# Pin
Xmen Real 19-Mar-09 4:35
professional Xmen Real 19-Mar-09 4:35 
AnswerRe: Send an email witch c# Pin
Jacob Dixon19-Mar-09 4:36
Jacob Dixon19-Mar-09 4:36 
AnswerRe: Send an email witch c# Pin
musefan19-Mar-09 4:37
musefan19-Mar-09 4:37 
GeneralRe: Send an email witch c# Pin
Xmen Real 19-Mar-09 4:42
professional Xmen Real 19-Mar-09 4:42 
GeneralRe: Send an email witch c# Pin
musefan19-Mar-09 4:46
musefan19-Mar-09 4:46 

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.