stretchable histogram overlaying a picture - wpf

I'm in the process of making a WPF program that:
can scan a bitmap image, pixel-by-pixel, and assign it a data value (0-255)
design a class that allows panning and zooming of the picture
create a histogram, from the data values, that overlays the bitmap image.
I was able to do all three, however the issue that I am having is that the histogram doesn't dynamically (I think that's the word for it) stretch as I re-size the main window. Actually, nothing stretches to the correct size in the main window (the bitmap image just re-centers itself while keeping the same size). The histogram originally started as a transparent canvas that had many rectangle children. I changed it to a grid but am getting the same results as the canvas; the rectangles don't want to stretch horizontally or vertically. If I do set a horz/vert alignment the histogram disappears altogether. Can anyone help with this problem?

I ended up making a class that was a derivative of the canvas class i cave it some rendering overrides and a paint method that took into account the actual width and height of the window.

Related

[XAML-WP8.1]Grid View background image clip to bounds

I'm new on Windows development and more in Windows Phone Development.
I'm trying to create a grid view composed of three cell.
Each grid view are composed of one image (for the background) and a textblock.
My background image is a cloud image and I want the first image partialy hidden by the second one and the second one partially hidden by the third one.
I tried to play with the margin of the cell for the y part, that's works but my cloud image doesn't make the entire width of my cell. So I tried the "UnifirmToFill" option but my images are cropped...
On iOS development in this case we can use the magic property "ClipToBounds", everywhere I saw the answer "use the clip to bounds property" but apparently this property is a legend or Visual Studio lie me...
Do you have an idea to resolve my problem ?
Thank you in advance!
To resume:
If I use the "uniformToFill" stretch option, my image is zoomed. It is ok for me.
But there is a way to display the cropped part? I want my image zoomed and displayed out the cell view.
In XAML there are four possible Stretch options:
None
The image is shown in it's original size. If its larger than the parent element, it'll only show the top left portion of the image that fits inside. If the image is smaller than the parent element, then it's shown in it's entirety.
Fill
The image is resized to fill the parent element. If the aspect ratios are different, then the image will be stretched to fit the parent. This will distort the image.
Uniform
The image will be scaled up as large as it can be, while still being completely inside of the parent. Unlike Fill which will stretch the image to make it fit perfectly, Uniform will keep the aspect ratio of the image and stop scaling when it reaches the bounds of the parent.
UniformToFill
This is the bastard child of the previous two. It will scale the image, while keeping the aspect ratio, until it fills the parent element. This means that some parts of the image will be clipped if the aspect ratios are different.
For more information on the Stretch enumeration, hit it up on MSDN
UPDATE
If you want to show the image outside of the bounds of the parent you could do something like this:
<Grid Width="100" Height="50">
<Grid.Clip>
<RectangleGeometry Rect="0 0 100 50"/>
</Grid.Clip>
</Grid>
This was suggested here on SO

Relationship between a canvas in silverlight and rectangle

I am new to silver light and would like to understand a bit more from the pros. Let me tell you what I am trying to do. I am into photography and my goal is to create a web site that allows users to view their images and be able to rotate, zoom, crop, special effect etc. I have developed the web site that allows users to order pictures but now I want to start working on the actual picture/image manipulation. So for testing i put a canvas and a rectangle( with an image). Placed a slider and was able to link the slider to the rectangle. As i increase the slider the image gets larger. But I was kind of hoping as the image gets larger it does not surpass the boundries of the canvas. I assumed that is what it means by being a child of a canvas. Am i mistaken? If so how do you suggest me doing this? Remember I am very new to this and may be going about this very wrong.
Thanks!
Your are right. In Silverlight (like in WPF, WinForms etc.) gui-elements form a hierarchy of elements wherein controls can act either as parents or as children.
The reason why your rectangle surpasses the boundaries of it's container lies in the way controls are getting aligned. This depends on what kind of container you want to place your child into.
In a canvas for example you position the children with absolute measurements (left, top, height, width). In a self-organizing container like the StackPanel you choose an horizontal alignment (Left, HCenter, HStretch, Right) or a vertical alignment (Top, VCenter, VStretch, Bottom) which determines the childs behavior when you place it inside the parent. Furthermore you can specify the dimension of the child (Width, Height) and an optional margin which determines the gap between the Top, Right, Bottom and Left bound of your child to its enclosing parent.
But what ever container you choose it's inherent to it that you can let its children surpass its boundaries e.g. with a margin that is negative or greater than the container boundaries or simply by an child that is bigger in dimension that its container as you described the situation with your rectangle.
In your case I would consider working with the idea of clipping. Clipping simply means to
(1) define an geometrical area (in Silverlight and WPF it is a Path object) which lies over some graphical context (some section of your ui or your control etc).
(2) what lies inside the boundaries of this clipping area remains visible and everything else remains invisible.
So you can think of a clipping area as a window onto your screen which you use to look through.
When you are using Microsoft Blend this is easy to realize:
(1) Just use a geometrical shape like a Rectangle, a Circle or a custom Path.
(2) Place it somewhere upon your UI
(3) Right-click the shape, select "Path" and then "Make clipping Path"
(4) and voulĂ , you've just defined a clipping area which you can modify as you are used to modify controls.
Hope this gave you an idea how to deal with your problem.
cheers.

Visual brush snap to device pixels

I have an application with a small overview window to navigate the canvas faster. On that window I display a flowchart with relations and decisions , etc... When the flowchart grows the overview window doesn't display the line's anymore this is because the line thickness is less then 1 px.
I've already tried to set the snap to device pixels on the lines,the canvas with the brush on it,but without success.
Is there an option to make the brush display the lines even if they are less thin then 1 px?
If I understand you correctly, you have essentially a minimap to navigate your Window. In which case, have a look at rendering controls as bitmaps: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
It should be pretty simple to render your canvas and display it in the overview window.

How to get Silverlight's bitmapimage pixel height before it is drawn to canvas?

I have an Image, which I need to scale based on the image's pixel values.
When I create the bitmapImage, the pixels (height and width) are both 0.
Is there a way to get height and width before the image is drawn to the canvas?
I had a similar issue where I needed to measure the height of a row (with content) being added to a Grid before adding it to the Grid. Short answer - it can't be done.
Long answer - it can be done. In my code-behind, I created a dummy Grid not a part of the UI. I would add the row to it, and then call .Measure on the dummy Grid that would give me the rendered size of the row. Then I could just add the row to the actual Grid on the UI.
I suspect you could try the same approach with your image. Create a dummy Canvas, add the image to the Canvas, and see how big it is.

WPF Clipping Problem

I have a UserControl which has a quadratic Image as a Child. This Image is at the bottom of the UserControl, and half of it is clipped (e.g. the Control's Height is 400, Image's height is 200 and it is set to y=300).
Now, When I rotate the Image, it is still clipped like the way it was first. Like when rotating around 90 degrees, I suddenly have an Image which is only 100px wide.
It seems like the original clipping which was made because of the bounds of the UserControl, are applied forever.
How do I solve this problem? I hope I explained my problem understandable ;)
How are you rotating the image? If you are rotating using a RenderTransform, then WPF does not re-render what was already displayed on the screen - it simply rotates the pixels.
Instead, rotate the image using a LayoutTransform; this forces WPF to re-render the control given the new area it occupies, which should eliminate the clipping you see.
You can also call InvalidateMeasure() after applying render transform.

Resources