Darken Frame Background on Desktop UWP with XAML & C# - c#

I am using user input images as the Frame Background in my app and I want to darken the image. Reducing opacity does the opposite and brightens the image as the Window color is white on Desktop and not black and I can't see any function to change the color of window.
Changing TitleBar Color doesn't work.
Changing the RequestedTheme from Light to Dark doesn't change the color.
Processing the image to darken is too slow and can't be used.
Here's the code to change the Frame background where 'image' is my BitmapImage object.
ImageBrush b = new ImageBrush();
b.ImageSource = image;
b.Stretch = Stretch.UniformToFill;
(Window.Current.Content as Frame).Background = b;
I need to use the Background on Frame and not on Page as navigation to other pages needs to be smooth and keep the background in place.

Related

Display image depending on application theme (Dark/light theme)

I am develop an UWP app, and I am using template10. I have two images, one white and other black. I want show black image in light theme, and white image in dark theme. I have this code:
if (this.RequestedTheme == ElementTheme.Light)
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/BlackImage.png"));
else
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/WhiteImage.png"));
But, when I choose light theme image dont appear! But when I choose dark theme, white image appears.
If we do not set the ElementTheme.Light or ElementTheme.Dark to the FrameworkElement.RequestedTheme, it will always return the ElementTheme.Default. So your Image will be set with WhiteImage, no matter the ApplicationTheme is Light.
The RequestedTheme in app that can gets or sets a value that determines the light-dark preference for the overall theme of an app. It returns ApplicationTheme of the enumeration. It includes Light and Dark. We should be able to use App.Current.RequestedTheme to get the current ApplicationTheme of the App.
For example:
var AppRequestedTheme = App.Current.RequestedTheme.ToString();
if (AppRequestedTheme == "Light")
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/BlackImage.png"));
else
Image.Source = new BitmapImage(new Uri("ms-appx:///Assets/WhiteImage.png"));

windows phone 8.1 header bar icon colours

My application is setting the Requested theme in the App.xaml as we only want to show a light theme regardless of what the user's system theme is.
Problem is, when the user is on a dark theme (which has white icons for signal/battery/time etc) the app switches all style resources to use light theme but does nothing about the header bar. This creates the situation where you have a white page background and white icons on top of it.
Is there a way to change the theme applied to this top bar?
I tried adding a dark colour behind the bar (30px high rectangle with margin -30 on top) but the behaviour happens on light theme too so then if the user is on light theme, the icons are black and too dark to see on the colour background.
It's not obvious in the picture, but on top of that map there is the header bar with icons but the icons are white and the theme says page background is white.
Turns out the correct answer is:
http://msdn.microsoft.com/library/windows/apps/windows.ui.viewmanagement.statusbar(v=win.10).aspx
This class also cannot be used from the XAML so you have to do:
public MainPage()
{
StatusBar statusBar = StatusBar.GetForCurrentView();
statusBar.ForegroundColor = new Windows.UI.Color() { A = 0xFF, R = 0xFF, G = 0x00, B = 0xAA };
this.InitializeComponent();
}

exclude a part of an image by taking color

My problem is quite simple, but I can't deal with it. I have a yin-yang.jpg file and I'd like to get only round shape (without rest of rectangle, which should be not clickable) and what is more whole white color change to red one and parts with black color should be excluded from an image as well (not clickable).
That image will be background of my form, which I'd like to show at the start of an application.
private void hello_form_Paint(object sender, PaintEventArgs e)
{
Form f = (Form)sender;
f.BackgroundImage = global::TicTacToe.Properties.Resources.ying_yang1;
GraphicsPath formPath = new GraphicsPath();
Rectangle newRectangle = f.ClientRectangle;
e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);
newRectangle.Inflate(-5, -5);
formPath.AddEllipse(newRectangle);
f.Region = new Region(formPath);
}
Paint event on my form which I show makes them round, but it's not all things I have to do. How to exclude a black part from a background and how to change white part into red one?
Given what you've described you may find:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.maketransparent(v=vs.71).aspx
Bitmap.MakeTransparent() a useful method to explore, it allows you to turn a given colour in your image transparent.
If you use a file with transparent background like a .png or .gif you should be able to only see the round yin-yang shape when you set it as form background.
You can easily edit a .jpg with i.e. GIMP or Photoshop to make the rectangle transparent outside the circle.
edit: is this what you are trying to do?

Change Color Alpha with Timer in C#

I have a WinForms app which the user can choose a color from the color picker.
(I'm using the color Dialog from the Toolbox).
Now when the user chose some color I'm painting some shapes on the form using the GDI
and bitmap.
Is it possible to change this color's alpha with a timer?
because all I see is the color Dialog returns a Color or just the current values of
A,R,G,B (alpha,red,green,blue) and those values cannot be set programmatically .
I know there is Color.FromArgb() method.
I thought about this code :
Color userColor = colorsDialog.Color;
Color c = Color.FromArgb(alphaValue,userColor);
When the alphaValue is set to zero, and on each timer tick incrementing it by 1.
but it doesn't work..
Edit: the shape is drawn on the bitmap.

PorterDuff.Mode.Multiply not working as intended? Black background instead of transparent

I have a problem with PorterDuff.Mode.Multiply, it seems that all alpha channels are set as 'black'. Is this as intended? In photoshop / gimp etc the effect leaves transparency where it should be. Darken leaves the transparency alone, but still applies the effect to values with RGB, this is what I want, but with Multiply's effect.
It's just the PorterDuff.Mode.Multiply that causes the black background problem with the overlay.
Bitmap photo = ((BitmapDrawable)ivPhoto.Drawable).Bitmap;
Bitmap overlay = ((BitmapDrawable)overlay.Drawable).Bitmap;
Point ss = getScaledSize(photo.Width, photo.Height, scrSize.X, scrSize.Y);
Bitmap bresult = Bitmap.CreateScaledBitmap(photo, ss.X, ss.Y, true);
Canvas myCanvas = new Canvas(bresult);
Paint myPaintStyle = new Paint(PaintFlags.FilterBitmap);
myPaintStyle.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply));
myCanvas.DrawBitmap(
overlay, //img
ivHair.GetX(), ivHair.GetY(), //x,y
myPaintStyle); //style
return bresult;
Help? :)
This is in Mono for Android
Edit: DstIn has the same undesirable effect. (alpha is black)
I had the same problem for an entire day. I was getting crazy .
What worked for me is this line of code:
yourView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Place it in the class constructor and now the black background should disappear.

Categories