2010-02-23 17 views
15

यूआरएल को इनपुट के रूप में प्रोग्राम किए गए वेबपृष्ठ का एक सेंसरशॉट कैसे लेता है?प्रोग्रामिंग के किसी वेबपृष्ठ का स्क्रीनशॉट लेना

और यहाँ मैं क्या अब तक है:

// The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap) 
Bitmap bitmap = new Bitmap(1024, 768); 
Rectangle bitmapRect = new Rectangle(0, 0, 1024, 768); 
// This is a method of the WebBrowser control, and the most important part 
webBrowser1.DrawToBitmap(bitmap, bitmapRect); 

// Generate a thumbnail of the screenshot (optional) 
System.Drawing.Image origImage = bitmap; 
System.Drawing.Image origThumbnail = new Bitmap(120, 90, origImage.PixelFormat); 

Graphics oGraphic = Graphics.FromImage(origThumbnail); 
oGraphic.CompositingQuality = CompositingQuality.HighQuality; 
oGraphic.SmoothingMode = SmoothingMode.HighQuality; 
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic; 
Rectangle oRectangle = new Rectangle(0, 0, 120, 90); 
oGraphic.DrawImage(origImage, oRectangle); 

// Save the file in PNG format 
origThumbnail.Save(@"d:\Screenshot.png", ImageFormat.Png); 
origImage.Dispose(); 

लेकिन यह काम नहीं कर रहा। यह केवल मुझे एक सफेद खाली तस्वीर दे रहा है। मुझे यहां क्या समझ नहीं आ रहा है?

क्या कोई अन्य तरीका है कि मैं प्रोग्रामिंग के वेब पेज का स्क्रीनशॉट प्राप्त कर सकता हूं?

+0

यह प्रश्न कल पूछा गया था, हालांकि मुख्य रूप से पर्ल में निर्देशित किया गया था। शायद कुछ जवाब आपको मदद करेंगे, हालांकि स्पष्ट रूप से आपको एक और दिशा ले जाएगा। यहां [लिंक] है (http://stackoverflow.com/questions/2312852/how-can-i-take-creenshots-with-perl)। – lundmark

उत्तर

7

मैं खोज की है और खोज की है और खोज की है और यह Webpage thumbnailer (एक The Code Project लेख) पाया।

+2

यह माइक्रोस्कोफ्ट वेब ब्राउज़र नियंत्रण का उपयोग करता है जो आपको अक्सर एक खाली सफेद स्क्रीनशॉट देता है – jjxtra

2

आप देशी PrintWindow फ़ंक्शन को कॉल करने का प्रयास कर सकते हैं।

+1

क्या आप इस पर कुछ और बता सकते हैं? कृपया ध्यान दें कि मेरे पास वेबपृष्ठ का यूआरएल इनपुट के रूप में है। – Manish

3

बिटमैप पर ब्राउज़र नियंत्रण ड्राइंग कुछ हद तक अविश्वसनीय है। मुझे लगता है कि बस अपनी खिड़की को स्क्रीनक्रैप करना बेहतर होगा।

using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb)) 
using (Graphics graphics = Graphics.FromImage(bitmap)) 
{ 
    graphics.CopyFromScreen(
     PointToScreen(webBrowser1.Location), 
     new Point(0, 0), 
     bitmapSize); 
     bitmap.Save(filename); 
} 
+3

यह दृष्टिकोण कंसोल ऐप में काम नहीं करेगा, है ना? –

0

तुम भी gdi32.dll से BitBlt() लागू पी की कोशिश कर सकते /। इस कोड का प्रयास करें:

Graphics mygraphics = webBrowser1.CreateGraphics(); 
Size s = new Size(1024, 768); 
Bitmap memoryImage = new Bitmap(s.Width, s.Height, mygraphics); 
Graphics memoryGraphics = Graphics.FromImage(memoryImage); 
IntPtr dc1 = mygraphics.GetHdc(); 
IntPtr dc2 = memoryGraphics.GetHdc(); 
// P/Invoke call here 
BitBlt(dc2, 0, 0, webBrowser1.ClientRectangle.Width, webBrowser1.ClientRectangle.Height, dc1, 0, 0, 13369376); 
mygraphics.ReleaseHdc(dc1); 
memoryGraphics.ReleaseHdc(dc2); 
memoryImage.Save(filename); 

पी/आह्वान होगा:

[DllImport("gdi32.dll")] 
[return: MarshalAs(UnmanagedType.Bool)] 
internal static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop); 
संबंधित मुद्दे