Applying color adjustments to an image - windows-phone-7

how I can apply color adjustment to an image in windows phone. Is there any free sdk is available that support color adjustment. In my application I need to apply a color shade to an image based on the color he selected from color pellet. Can anyone please help me to implement such functionality in windows phone.

Place a rectangle over the Image and set its opacity to 60%. (It is easier if you use Expression Blend for this part).
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Margin="188,208,168,299" Source="wifi-signal.jpg"/>
<Rectangle Name="Rect1" Fill="Blue" Margin="188,208,167,299" Stroke="Black" Opacity="0.595"/>
</Grid>
In the Code View, you can trigger an event, to change the color of the Rectangle using the following code:
Rect1.Fill = new SolidColorBrush(Colors.Red);

Related

Image within an ellipse XAML

I am using VS2013, Windows 8.1 and developing a windows store app.
Im creating a simple contacts - listview, that displays the contact details along with contact image within an ellipse. When I click on the listview item, I want to display the contact details on right side of the page. Now the issue I am facing is, I am not able to fit the contact image to the right size on the ellipse on the right side pane.
I am able to achieve it in my list view since its an smaller ellipse.
Important: I do not want the image to look stretched/Zoomed in /Zoomed out. It should exactly look like how it appears within the list view. (For list view , I have used Ellipse.Fill along with Imagebrush, but relatively smaller sized ellipse)
What I tried so far:
Ellipse.Fill property which paints the image to size, but the image looks stretched.
I tried setting "Stretch" property within the image tag within ellipse, but did not work.
I tried Image.clip, but I do not have "EllipseGeometry" option, instead only RectangleGeometry.
Lastly I created an image that has a transparent center and I place this frame over the contact image like a mask. This works well on some resolutions. But when some other resolution, the contact images which are binded from backend, go beyond the frame, although I set "MaxHeight" or "Height" properties.
I want to do it the right way, since I feel adding an image mask might not be a great way to achieve this. Please help!
I tried this for listview, n works fine, But the same code for right pane looks stretched (I have tried removing stretch attirbute, or tried other options like Stretch ="None" /"Uniform" etc )
I have attached screenshot.
Since code isn't clearly mentioned, you can do it with both Ellipse and Border. Here's the code snippet
<!--With Ellipse-->
<Ellipse Height="200"
Width="200">
<Ellipse.Fill>
<ImageBrush Stretch="Uniform"
ImageSource="Assets/profile.png" />
</Ellipse.Fill>
</Ellipse>
<!--With Border-->
<Border Height="200"
Width="200"
CornerRadius="150">
<Border.Background>
<ImageBrush Stretch="Uniform"
ImageSource="Assets/profile.png" />
</Border.Background>
</Border>
Here's the result
The properties "AlignmentX AlignmentY" within ImageBrush solved my issue.
If your image has portrait orientation, then you can use Stretch, AlignmentX, AlignmentY properties of ImageBrush like this to achieve best preview result
<Border CornerRadius="20" BorderThickness="1" BorderBrush="DarkGoldenrod">
<Ellipse Width="40" Height="40">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding PractitionerPhoto}" Stretch="UniformToFill" AlignmentX="Center" AlignmentY="Top" />
</Ellipse.Fill>
</Ellipse>
</Border>

Xamarin Forms Controls with borders

In my Xamarin forms application I want to add borders to a Grid / StackPanel. Also the background color will be transparent. I used frame control , but when I set background color to transparent the border also not shown. Please help me?
You basically have two possibilies, since this is not yet supported in Forms, where the first is to use BoxViews as explained on SO in this post.
Otherwise, you can wrap a StackLayout around your View (the StackLayout or Grid as you mentioned) with a BackgroundColor and Padding of 0.5 as explained here.
Let me know if you need more concrete examples.
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add to the grid have own BackgroundColor set correctly.
A BoxView can be used for border purpose. In the following XAML code, note that FillAndExpand option is used for HorizontalOptions of the StackLayout
<StackLayout VerticalOptions="Start" HorizontalOptions="FillAndExpand" >
<BoxView BackgroundColor="Cyan" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
<BoxView BackgroundColor="Cyan" HeightRequest="1" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />
</StackLayout>
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set
grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add
to the grid have own BackgroundColor set correctly.
You also have to set Grid.Padding to whatever the border width you want.

How to Change Foreground Color of Image in View

I have a horizontal StackPanel of an Image and TextBlock. What I need to accomplish is changing the foreground of both to a certain color. I can easily change the TextBlock with the Foreground property, but I am not sure how to do this with an Image. The image is just a basic app icon.
<StackPanel Orientation="Horizontal">
<Image Source="/Assets/Icons/appbar.book.perspective.png" Width="50" Height="50" Margin="-8,0,-6,0"/>
<TextBlock Text="BOOK" VerticalAlignment="Center" Foreground="Blue"/>
</StackPanel>
BitmapIcon is helpful for what you can use instead:
<BitmapIcon Width="20" Height="20" Foreground="Red" UriSource="ms-appx:///Assets/Resources/YourImage.png" />
That's my way...:)
Instead of having an ImageViewer and Textblock use Grid and Textblock.
Give the background of grid as desired image source.Place a Textblock inside the grid.And assign the text to the TextBlock inside the grid.
You can accomplish your task.
Do you want to change image background color then take image with transparent backround and set code as below
<StackPanel Orientation="Horizontal">
<Grid Background="Blue" Width="50" Height="50" Margin="-8,0,-6,0">
<Image Source="/Assets/Icons/appbar.book.perspective.png" />
</Grid>
<TextBlock Text="BOOK" VerticalAlignment="Center" Foreground="Blue"/>
</StackPanel>
You can't set the foreground of an image. The color of the image is imbedded in the png file.
What you could do is create a filter and put it over a colored backgroud. Suppose you've got an image of a book in black (foreground) and white (background). If you want the book to be blue (foreground) you first create a filter with a white background and a transparant foreground. Then you put that filter on a blue grid like this:
<StackPanel>
<Grid Background="Blue" Width="50" Height="50" Margin="-8,0,-6,0">
<Image Source="/Assets/book.white.filter.png"/>
</Grid>
</StackPanel>
If you have to support both black and white theme's you'll need to creat a filter with a black background and a transparant foreground as well. Then you'll have to set the source of the image according to the selected theme.
It might be simpler to create a copy of the image and edit it in Photoshop, GIMP or Paint.NET. These apps have tools for swapping pixel colors.
Then you can either swap out the image URI to switch the image. Or you can overlay the foreground color image overtop of the main image, setting its Visibility=Collapsed. Then set Visibility=Visible as needed.
If you are using the standard black/white app icons, they have versions that are white-on-black and black-on-white.

How to set rounded corners for an image control?

Background
I'm a noob on Windows Phone 8. I've learnt WPF and Silverlight in the past, but it was long ago.
On Windows phone 8, I have a clickable Image control which I wish to have its content (the picture itself) to have rounded corners.
The question
How do I set rounded corners to a control?
Also, I might consider having a Button control instead, so that I could customize what happens when it is being clicked (or touched). Upon clicking, I would like that the area that has the rounded corners would be colored in some color, showing that it was indeed being clicked/touched. How do I do that?
EDIT:
Thanks to #Depechie, I've found this solution:
<Grid>
<Border Height="200" Width="250" CornerRadius="0,0,50,50">
<Border.Background>
<ImageBrush ImageSource="Images/Desert.jpg" />
</Border.Background>
</Border>
</Grid>
However, I have two problems with that:
I still can't find how to make it seen as clicked when you touch it, so that the rounded corners would have a yellow background.
I can't get the imageSource and the converter (and its parameter) via code when handling the clicking event. Previously, I've used:
Image thumbnailImage = (Image)sender;
var bindingExpression = thumbnailImage.GetBindingExpression(Image.SourceProperty);
string selectedItem = (string)bindingExpression.DataItem;
string selectedThumbnailIndex = (string) bindingExpression.ParentBinding. ConverterParameter;
Maybe I could create the items programmatically instead of Xaml? If so, how (items are in a grid, btw)?
What can I do now?
Try this by using Rect
<Image VerticalAlignment="Center"
HorizontalAlignment="Center"
Stretch="None"
Source="Jellyfish.jpg">
<Image.Clip>
<RectangleGeometry RadiusX="5"
RadiusY="5"
Rect="0,0,150,113"/>
</Image.Clip>
</Image>
Here is the another link
https://msdn.microsoft.com/en-us/library/ms750631(v=vs.110).aspx
There is a similar question listed here...
Maybe those can help you too?
And if you want to have the ilusion that the image is a clickable control, take a look at TiltEffect that is available in the Phone toolkit
Instead of attempting to alter the shape of a control (Which after looking in VS and Blend I dont think is possible) Why not simply create your image with rounded edges and then set the button border and background to no color?
For the rounded corners, you can set the RadiusX and RadiusY values to nonzero numbers to achieve that effect in a rectangle. So I imagine you could embed a button inside the rectangle if you want to keep the button control.
<Image Width="25" Height="25" VerticalAlignment="Center"
HorizontalAlignment="Center"
Stretch="Fill"
>
<Image.Clip>
<RectangleGeometry RadiusX="12.5"
RadiusY="12.5"
Rect="0,0,25,25"/>
</Image.Clip>
</Image>
The corner radius should be half of width or height.

Why won't controls stretch in WP7?

Here is a simple XAML snippet:
<Grid x:Name="ContentGrid">
<ContentControl Background="Yellow" VerticalAlignment="Stretch"></ContentControl>
</Grid>
In WPF, the content control stretches the entire height of the grid.
In WP7 however, the content control does not stretch.
Why?
Avoid using ContentControl directly.
If you use something which inherits from it, such as a button, then, in a grid, as per your example, you'll automatically get horizontal and vertical stretching.
This will creat a button with a yellow background which fills the screen:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Background="Yellow" />
</Grid>
However, if you just wanted a yellow background to your grid - which is all your sample would do - you could just set the background property on the grid itself.
I fixed this by defining my own template:
<ContentControl><ContentControl.Template><ControlTemplate><ContentPresenter/> ...
Not sure why it fixes it but it works....

Resources