I have listview of images in different resolution. I would like to do something that width of picture will be auto and heigth will be 75% or something of width. Images will be autoscale to this resolution.
You could create an IMultivalueConverter instance, which would accept the ActualWidth value of your ListView, and the image itself.
The converter would manipulate the Bitmap and it could be rendered with the desired parameters.
Related
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.
I have an Image control with Stretch==Uniform which means larger images will be scaled down. In my case the Image control fills the whole client space, the scaled down image is being displayed centered inside the control. What now will happen: the size of the rendered image and the Image control do not have the same size - the Image control is usually larger than its content (since I use uniform stretching).
I now need to know the position of the actual image inside the Image control. Some background: the user can place a rectangle on the image to crop it. To match the rectangle with the image coordinates I need to know exactly where the image is.
Is there a way to determine the position of the rendered image inside the Image control? Or is the only solution to make the control the same size as the image content?
To get more control, you might want to put the image on a canvas inside a viewbox.
That way you get pixel control via the canvas, but a scaled view via the outer viewbox. Set the canvas dimensions to match the image and add any decorations to the canvas.
You may need to inverse-scale the rectangle stroke width so that it is visible when the canvas is small.
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.
I have a pixel perfect control layout for a form I want to create. I know the exact width, height and location of each control.
But I am finding it difficult to set it perfectly inside a Window element.
The Width and Height property of the Window is including the borders. How can I set the inner width and height of the window? The Client width and height.
Say, my form is 300px wide. If I set the width and height of the Window to 300, then the borders take up anywhere from 5 - 15px and only 285 or so pixels are available for the client area where you can add controls. I want to set this client area's width to 300px.
I tried having a container control like a Grid or StackPanel and set its width to 300px and setting the window's widthto auto. But the window was way too wide.
Hope I am making sense.
How can I do it?
Your approach of setting an inner panel width and letting the window size itself accordingly is correct. What you probably might have missed is the property SizeToContent of the window. Set SizeToContent="WidthAndHeight" and it will work.
Before asking this question I have looked at all related questions, but have not found anything relevant.
In my application I have toolbox style bar, which is basically stack panel with bunch of buttons. User may change which buttons are shown in toolbar.
Window width may be changed, but it can not be smaller then width of toolbar.
At first I was hoping to bind the MinWidth property to the StackPanel Width property and create converter that adds few pixels to Width of the StackPanel. The problem is that my converter does not get Width of StackPanel, just NaN as value :(
Unfortunately, StackPanel width is set to Auto and I can not change that.
Is there any way I can make my Window MinWidth dependable on Width of StackPanel?
Use ActualWidth, not Width.
Width is the requested width, or NaN for "Auto", ActualWidth is the, well, actual width after all the layout is calculated.