Results 1 to 9 of 9

Thread: Printscreen & Then Save JPG

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    72

    Printscreen & Then Save JPG

    how i would save my screen as a Jpg image ...

    the quality of the jpg is 50%
    Last edited by ayman_rapper; May 27th, 2005 at 12:34 PM.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Printscreen & Then Save JPG

    dunno about the print screen. But to save a jpeg with a certain quality:
    Code:
    /// <summary>
    		/// Only for JPEG format.
    		/// </summary>
    		/// <param name="quality">from 0 to 100.</param>
    		public static void GetImgQualityParams (int quality, out ImageCodecInfo imageCodec, out EncoderParameters encoderParams)
    		{
    			if (quality<0  ||  quality>100)
    				throw new ArgumentOutOfRangeException("quality must be between 0 and 100.");
    
    			// Get an array of ImageEncoders.
    			ImageCodecInfo[] imgCodecs = ImageCodecInfo.GetImageEncoders();
    			encoderParams = new EncoderParameters(1);
    			
    			EncoderParameter imgQuality = 
    				new EncoderParameter (Encoder.Quality, quality);
    
    
    			// Set the quality
    			encoderParams.Param[0] = imgQuality;
    			// JPEG format is index 1
    			imageCodec = imgCodecs[1];
    		}
    you have that function and as an example you could use it like this:

    Code:
    Image img = img.FromFile ("c:\\whatnot.bmp");
    ImageCodecInfo codecInfo=null;
    EncoderParameters encoderParams=null;
    GetImgQualityParams (batchInfo.JpegQuality, out codecInfo, out encoderParams);	
    img.Save ("C:\\whatnot.jpg", codecInfo, encoderParams);
    hope it helps
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    72

    Re: Printscreen & Then Save JPG

    Error 1 The type or namespace name 'ImageCodecInfo' could not be found (are you missing a using directive or an assembly reference?)

    Error 2 The type or namespace name 'EncoderParameters' could not be found (are you missing a using directive or an assembly reference?)

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Printscreen & Then Save JPG

    learn to use the Object Browser in vs.net, it's helpful
    you need to import a namespace:
    put this at the top of the code
    using System.Drawing.Imaging;
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    72

    Re: Printscreen & Then Save JPG

    Still there are some problems ...
    pls attach a sample for the code ..
    and thank u .........

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printscreen & Then Save JPG

    You can try this line of code to get a screenshot:
    VB Code:
    1. SendKeys.Send("+({PRTSC})");
    which sends the keystroke combination Shift+PrintScreen to your application. This should capture the entire screen. If you want just your app window, try this instead:
    VB Code:
    1. SendKeys.Send("{PRTSC}");
    You can then access the image via the clipboard. Lookup the Clipboard class in the help to learn how to retrieve the image.

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Printscreen & Then Save JPG

    sendkeys is SLIGHLY stupid as it makes you modify your clipboard to get the screenshot. But if you don;t know any other way then I guess that's it

    here's a sample project
    Attached Files Attached Files
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    72

    Re: Printscreen & Then Save JPG

    thanks

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Printscreen & Then Save JPG

    see this for capturing the screen, if you want to do it the "right" way. it uses windows API calls:
    http://www.developerfusion.com/show/4630/
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width