Is there a way to prevent from Windows AutoScale my forms? - c#

One of my forms takes screenshot of desktop and uses it as form background for drawing on it. But when the Windows setting "Desktop/Screen resolution/Make text and other items larger or smaller" is greater than 100% the Screen.Bounds is smaller then Image.Size. So the background image is bigger than form. Streching the screenshot image couses blurring.
So what is the solution for proper size screenshot?
Preventing Windows from AutoScaling my form or another way of screenshot?
SendKeys.SendWait("{PRTSC}");
Image img= Clipboard.GetImage();
this.BackgroundImage = img;
Debug.Print("Img.Size=" + img.Size.ToString());
Debug.Print("Screen.Size=" + Screen.PrimaryScreen.Bounds);

Related

Zoom performance in C# Bitmap

I'm working with C# WinForms app and using custom control for displaying bitmap images. The problem is, when zooming images I'm using MouseWheel event and, creating new Bitmap image, based on new width and height properties.
On small and average images that works fine, but when size of image is about 3000*3000 pixels or greater, I have serious performance problems in line
scaledImage = new Bitmap(baseImage, size);
Where size - new size of image and baseImage - my original .png image.
So, maybe exists some another solution for such scaling?
Also I must mention that I'm limited with .net 3.5

How to display scaled image without anti-aliasing?

Question
How can I scale an image in XAML quickly without anti-aliasing applied?
Background
I am trying to make a pixel editor as a Windows 8 XAML/C# app. I'm using c#/XAML because most of my experience is with c#/WPF.
Method 1: WriteableBitmap + Image control. Originally, I used a WriteableBitmap to store and edit an image. That image is displayed in a resized XAML Image control. The problem is that the image does not get scaled properly because of anti-aliasing. (XAML does not seem to provide the BitmapScalingOptions that are available in WPF)
Method 2: Redrawn WriteableBitmap + Image control. Next I tried writing my own scaling, where I take my original image and write to a larger WriteableBitmap so that the scaled image is pixelated. The scaled image is then presented inside a XAML Image control. This process is slow and inefficient.
Method 3: SharpDX + Direct2d ?? I am pretty sure a solution exists somewhere between SharpDx, SurfaceImageSource, and Direct2d. Event still, I can't quite figure out how to display a SharpDx.WIC.Bitmap inside a Windows.UI.Xaml Image control, and am generally getting lost in the documentation.
What exactly is a recommended setup for achieving my desired end? Are there c# samples available which might point me in the right direction?
I don't know if you mean by scaling it by resizing it with the mouse or just with a button click to auto scale to a predetermined size.
But the thing you can do is to use an Image panel and then, just set it to image.Stretch = Stretch.Fill; so if you override and create a method for the Resize event of the Image Panel, your image will take the size to fill the Image panel.

Setting ImageSource in Coding4Fun RoundButton Not Scaling

I am trying to create a button that is the exact same look and feel as a regular Windows Phone 8 application bar button. I am using the Coding4Fun RoundButton for this. My issue is that when setting the ImageSource I cannot get the image to scale to fit inside of the button properly, it is far too big. I am using a standard application bar icon image from the Windows Phone 8 SDK, whch is 76x76. I've also resized to mimic the Windows Phone 7 icon size of 48x48 but the same result occurs. How can I adjust the image so it fits in the RoundButton properly?
XAML
<c4f:RoundButton x:Name="browseRoundButton" Click="Browse_Click"/>
XAML.CS
if (Settings.LightTheme.Value)
browseRoundButton.ImageSource = new BitmapImage(new Uri("/Assets/Icons/feature.search.light.png", UriKind.Relative));
else
browseRoundButton.ImageSource = new BitmapImage(new Uri("/Assets/Icons/feature.search.dark.png", UriKind.Relative));
EDIT* In referencing sources like http://www.geekchamp.com/articles/wp7-roundtogglebutton-and-roundbutton-in-depth and http://coding4fun.codeplex.com/discussions?searchText=roundbutton I cannot seem to find any solutions.
My solution to this was to set the ImageSource in the XAML (using only the dark style icon) and ensure the size is 48x48. Works Great!

How can I set a transparent image to my form's background in c#?

I made a transparent background image in photoshop but when I use it as my form's background image,it doesn't use form's back color(blue),so that I cannot use this code to make a transparent form.
this.BackColor = Color.blue;
this.TransparencyKey = Color.blue;
If I use white color instead,my other tools fore color face problem.I'm trying to make windows form app.I don't know if there are easier & better alternatives to make a transparent form.
What should I do?
Referencing a post from here and my own experience with having trouble on form transparency with types of images I expect it's because it's the fact it's JPG and not PNG or some other transparent friendly image format. I had the same problem and when I changed to PNG format it worked for me.
Reading results from a couple of random google searches it seems JPEG doesn't support transparency do to file format limitations.
Why am I getting a black background around my images when resizing even when Bitmap is set to Graphics.Clear(Color.Transparent)

DrawToBitmap on windows xp

I have a user control that shows plate number of a vehicle(it contains a background image and some TextBoxes), I use DrawToBitmap() Method to get a bitmap of this control and show the bitmap on my form, It works fine on Windows 7 but in Windows XP service pack 3 only background image is drawn and texts in textboxes are not drawn, what should I do?
var clt = new ControlLisenceTouch();Bitmap b = new Bitmap(clt.Width, clt.Height);
clt.License = License.FromCar(someCar);
clt.Invalidate(true);
clt.DrawToBitmap(b, Rectangle.FromLTRB(0, 0, clt.Width, clt.Height));
pictureBox1.Image = b;
This guy had the same sort of problem, and while the answer is not perfect, it did do it for him. The biggest problem here was that if another window was covering your control, that window would be shown as well. Look at my answer, the third edit shows taking a screen shot, and cropping a control out of it.
How can I get a screenshot of control? DrawToBitmap not working
According to http://msdn.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap.aspx
Windows XP sp3 is fully supported

Categories