How to take all screenshot from Panel in mono C# ?
I need not used winAPI.
My panel can not be fully visible.
Your question is not exactly clear but in case you meant taking a screenshot of the desktop: below is a small example of how you could do this using gtk:
using Gtk;
...
Gdk.Window window = Gdk.Global.DefaultRootWindow;
if (window!=null)
{
Gdk.Pixbuf pixBuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8,
window.Screen.Width, window.Screen.Height);
pixBuf.GetFromDrawable(window, Gdk.Colormap.System, 0, 0, 0, 0,
window.Screen.Width, window.Screen.Height);
pixBuf.ScaleSimple(400, 300, Gdk.InterpType.Bilinear);
pixBuf.Save("screenshot0.jpeg", "jpeg");
}
hope this helps, regards
Related
There are other similar questions, but they deal with only screenshotting the displayed application. My application is transparent, so I need to take a screenshot of both the displayed window and the background behind it.
This function correctly screenshots the app on my main monitor, but when it goes to the other monitor, the screenshots are the wrong shape and are completely black. If the window is partly on the monitor, then it still works, but as soon as the other monitor takes control of the window, I get black screenshots. How do I get the screenshots to render correctly?
Here is my function:
public void SaveSnapshot2(int count)
{
string imageName = "image" + count.ToString() + ".jpeg";
string basePath = Path.GetFullPath(Environment.CurrentDirectory);
string folderPath = Path.Combine(basePath, "Snapshots");
string fullPath = Path.Combine(folderPath, imageName);
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
System.Windows.Point relativeWindowPosition = App.Current.MainWindow.PointToScreen(new System.Windows.Point(0, 0));
System.Windows.Point relativeBottomRightWindowPosition = App.Current.MainWindow.PointToScreen(new System.Windows.Point(App.Current.MainWindow.Width, App.Current.MainWindow.Height));
System.Windows.Point actualWidthHeight = new System.Windows.Point((relativeBottomRightWindowPosition.X - relativeWindowPosition.X), (relativeBottomRightWindowPosition.Y - relativeWindowPosition.Y));
System.Drawing.Size convertedSize = new System.Drawing.Size((int)actualWidthHeight.X, (int)actualWidthHeight.Y);
Bitmap Screenshot = new Bitmap((int)actualWidthHeight.X, (int)actualWidthHeight.Y, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(Screenshot))
{
// Crops the screenshot
// The relativePoint is where the top left corner of the image is. This is correct.
g.CopyFromScreen((int)relativeWindowPosition.X, (int)relativeWindowPosition.Y, 0, 0, convertedSize); // or (0, 0, 0, 0, Screenshot.Size) to get the whole bitmap image
}
try
{
Screenshot.Save(fullPath, ImageFormat.Jpeg);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ", the image did not save.");
}
Screenshot.Dispose();
}
Coming up with names for the points was difficult. I hope they are clear enough.
Does the coordinate system change when a window is on a separate monitor? Am I going about this the right way?
I guess you have not declared DPI awareness in the application manifest. It's a common pitfall when you have multiple monitors of different DPI. If have not, most methods and functions related to screen coordinates will return incorrect values and thus the calculation based on those values will be screwed up.
To solve this, add the application manifest which declares DPI awareness. See Setting the default DPI awareness for a process. PerMonitorV2 is the key for Per-Monitor DPI.
I have an EncodedImage. I want to draw a FontImage over it to get another EncodedImage. It’s similar to a LayeredLayout (a layer over another layer), but in this case I need a new EncodedImage with the two images merged.
Thank you
Use a mutable image.
Image img = Image.create(encImage.getWidth(), encImage.getHeight(), 0);
Graphics g = img.getGraphics();
g.drawImage(encImage, 0, 0);
g.drawImage(fontImage.scaled(encImage.getWidth(), encImage.getHeight()).toImage(), 0, 0);
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer, "Monthly sales in the last 1 years", "Cars", "sold", 0, 5, 0, 100, ColorUtil.GRAY, ColorUtil.LTGRAY);
renderer.setXLabels(1);
renderer.setYLabels(5);
renderer.setBarWidth(40);
renderer.setLabelsTextSize(8.0f);
Label text size is not rendering in Bar Charts?
You are setting the text size to 8 pixels which will make it pretty small and might not work if your fonts aren't native fonts. Try something like this.
renderer.setLabelsTextFont(Font.createTrueTypeFont("native:MainThin", "native:MainThin"));
renderer.setLabelsTextSize(convertToPixels(5));
I'm using gtk3 in Anjuta with C, with the following cut-out version of my code:
u.wMenuButton = gtk_menu_button_new();
u.weaponMenu = gtk_menu_new();
u.weaponCI = gtk_menu_item_new();
u.weapon = gtk_button_new_with_label("Punch");
gtk_box_pack_start(GTK_BOX(u.horizontal), u.wMenuButton, TRUE, TRUE, 1);
gtk_menu_button_set_popup (GTK_MENU_BUTTON(u.wMenuButton), u.weaponMenu);
gtk_container_add (GTK_CONTAINER(u.weaponCI), u.weapon);
gtk_menu_attach(GTK_MENU(u.weaponMenu), u.weaponCI, 0, 1, 0, 1);
The only difference in my real code is that I used an array of "weaponCI" and "weapon" and formatted each one identical to the above. I've tried NOT using an array, but it didn't work. I've tried different menu_attach column and row combinations, and nothing worked. I've tried using menubars as indicated in tutorials, and it didn't make a difference. I've reviewed the documentation and some tutorials, and I can't figure out what I have wrong.
I've almost completely sure that my headers and everything is fine, and nothing but the menu is working wrong.
However, the menu still pops up as a tiny flat rectangle with nothing in it at the corner of the screen.
Well, did you try to call gtk_widget_show_all on it ?
I'm trying to draw a 400x400 px image to a 400x400 form that I made. What I'm doing is:
Graphics.DrawImage Method (Image, 0, 0, 400, 400) 0, 0, 400, 400, ...
But when I run the form, the image seems to stretch slightly upon the y-axis, the x-axis seems to be working correctly.
This was what I was doing before (stretching the old smaller images to fit the size)
... (Image, 0, 0, 264, 231) 0, 0, 400, 400, ...
or something like that. Now that I'm trying to do it the correct way, I can't seem to get it to work properly.
Edit: I wonder if using a simpler verson of Graphics.DrawImage would work? Although I still need to figure out what is wrong with what I'm doing.
Thanks in advance.
If you have a borderless form at 400 x 400, then it should be ok.
If not, then you have to account for the non-client dimensions of the form to reach the size you want.
You can just do this for drawing:
e.Graphics.DrawImage(image, 0, 0)
To set your form size, you can try this:
Me.ClientSize = New Size(400, 400)