Autor |
Beitrag |
MartinBush
![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 46
|
Verfasst: Di 11.11.08 13:10
Mit folgendem Code mache ich einen Screenshot meines Bildschirms (CF)
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| public static void Snapshot(string fileName, Rectangle rectangle) { IntPtr deviceContext = GetDC(IntPtr.Zero); using (Bitmap capture = new Bitmap(rectangle.Width, rectangle.Height)) using (Graphics deviceGraphics = Graphics.FromHdc(deviceContext)) using (Graphics captureGraphics = Graphics.FromImage(capture)) { BitBlt(captureGraphics.GetHdc(), 0, 0, 640, rectangle.Height, deviceGraphics.GetHdc(), 70, rectangle.Top, SRCCOPY); capture.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); }
} |
Ich hab nun hin und her probiert und auch schon mit StrechBlt probiert aber ich kann das Bild einfach nicht verkleinern (auflösung). Habt ihr nen Tipp?
P.S. www.codeproject.com/...lus/imageresize.aspx hat mir nicht geholfen
Mfg Martin
|
|
Kha
![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 3803
Erhaltene Danke: 176
Arch Linux
Python, C, C++ (vim)
|
Verfasst: Di 11.11.08 16:09
StretchBlt sollte schon die richtige Richtung sein. Wo drückt denn der Schuh, wie weit bist du schon gekommen?
_________________ >λ=
|
|
MartinBush ![Threadstarter Threadstarter](./graphics/viewtopic/threadstarter.png)
![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 46
|
Verfasst: Di 11.11.08 16:42
Also mein Problem ist das ich ja einen neues Graphic Objekt erstellen muss - daran hänge ich. Also HDC hdcDest.
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| BOOL StretchBlt( HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, DWORD dwRop ); |
|
|
Kha
![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 3803
Erhaltene Danke: 176
Arch Linux
Python, C, C++ (vim)
|
Verfasst: Di 11.11.08 18:29
Du kannst doch einfach den BitBlt-Aufruf durch StretchBlt ersetzen und die Parametern anpassen?
_________________ >λ=
|
|
MartinBush ![Threadstarter Threadstarter](./graphics/viewtopic/threadstarter.png)
![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 46
|
Verfasst: Mi 12.11.08 11:42
Anbei mal mein gesamter Code um einen Screenshot zu erstellen und das aufgenommene Bild gleich zu skallieren.
Ich denke das ich IntPtr hdcDest noch erstellen muss oder? Ansonsten ist Quelle ja gleich Ziel. Also wie sollte denn mein Aufruf StretchBlt aussehen?
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:
| public class Capturer { [DllImport("coredll.dll")] public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
[DllImport("coredll.dll")] private static extern IntPtr GetDC(IntPtr hwnd);
const int SRCCOPY = 0x00CC0020;
[DllImport("gdi32.dll", SetLastError = true)] public static extern int StretchBlt(IntPtr hdcDest, int nXDest, int nYDest,int nWidthDest, int nHeightDest, IntPtr hdcSrc, int nXSrc, int nYSrc, int nWidthSrc, int nHeightSrc, uint dwRop);
public static void Snapshot(string fileName, Rectangle rectangle) { IntPtr deviceContext = GetDC(IntPtr.Zero); Bitmap newImage = new Bitmap(newImage.Width, newImage.Height);
using (Graphics deviceGraphics = Graphics.FromHdc(deviceContext)) using (Graphics captureGraphics = Graphics.FromImage(capture)) {
StretchBlt(captureGraphics.GetHdc(), 0, 0, 200, 100, deviceGraphics.GetHdc(), 70, 0, 570, 480, SRCCOPY); }
capture.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); }
} |
|
|
Kha
![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Kha hat insgesamt 95.6% On-Topic und 4.4% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 3803
Erhaltene Danke: 176
Arch Linux
Python, C, C++ (vim)
|
Verfasst: Mi 12.11.08 13:33
So sollte es stimmen. Was passiert denn?
Edit: Mal abgesehen von der Zeile
C#-Quelltext 1:
| Bitmap newImage = new Bitmap(newImage.Width, newImage.Height); |
Die gibt so wenig Sinn. Ein anderer Leichtsinnsfehler ist auch noch drin, aber den solltest du selbst finden können.
_________________ >λ=
|
|
MartinBush ![Threadstarter Threadstarter](./graphics/viewtopic/threadstarter.png)
![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 46
|
Verfasst: Mi 12.11.08 13:41
Ja die Zeile mit dem newBitmap muss raus.
Es wirft eine Exeption und das erzeugte Bild ist schlicht schwarz
|
|
Chryzler
![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. half ontopic star](./graphics/ranks/star_onofftopic.png)
Beiträge: 1097
Erhaltene Danke: 2
|
Verfasst: Mi 12.11.08 16:16
|
|
MartinBush ![Threadstarter Threadstarter](./graphics/viewtopic/threadstarter.png)
![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![MartinBush hat insgesamt 100.0% On-Topic und 0.0% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png)
Beiträge: 46
|
Verfasst: Mi 12.11.08 16:37
Mit Refernez auf : msdn.microsoft.com/e....copyfromscreen.aspx
wüßte ich nicht wie man die gewünschte Auflösung festlegen kann, es geht hier bei meinem Problem nicht um den Ausschnitt der aufgenommen werden soll sondern um die spätere Skalierung.(es soll nichts weggeschnitten werden)
Mfg
|
|
Chryzler
![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. ontopic star](./graphics/ranks/star_ontopic_full.png) ![Chryzler hat insgesamt 84.2% On-Topic und 15.8% Off-Topic Beiträge geschrieben. half ontopic star](./graphics/ranks/star_onofftopic.png)
Beiträge: 1097
Erhaltene Danke: 2
|
Verfasst: Mi 12.11.08 17:43
Die Skalierung machst du genau so, wie es in dem von dir verlinkten CodeProject-Artikel erklärt wird.
In Kurzform:
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| private void SaveScreenshot(string filename, Size size) { using (Bitmap bitmap = new Bitmap(1280, 1024)) using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size); graphics.DrawImage(bitmap, new Rectangle(Point.Empty, size), new Rectangle(Point.Empty, bitmap.Size), GraphicsUnit.Pixel); new Bitmap(bitmap, size).Save(filename); } } |
Wie man die Bildschirmauflösung ausliest weiß ich momentan nicht, also sowas natürlich auf keinen Fall hardcoden. ![;)](images/smiles/icon_wink.gif)
|
|
|