I'm trying to make zoom in/out buttons, but for whatever reason I just can't figure out how to maintain the aspect ratio and resize the image by - say 90% or 110%
The issue is that I'm trying to make it so that when you click the zoom out button 4 times, then click the zoom in button 4 times, the image would be its original size. There's no defined width since I'm trying to make the new width be 90%/110% of the existing width, but obviously multiplying by 0.9 and 1.1 doesn't do that correctly.
I currently have the following code..
Dim source As New Bitmap(PictureBox1.Image)
Dim NewWidth As Integer = source.Width * 0.9
Dim NewHeight As Integer = NewWidth * (source.Height / source.Width)
Any help is appreciated. I'm sure I'm just over-thinking it again, but some guidance would be appreciated :)
The best approach is to begin each resize operation with a copy of the original image. Have your buttons represent the total zoom factor (so say add 0.1 zoom for the + and subtract 0.1 zoom for the -).
You want to start with the original image each time because otherwise successive operations will quickly distort the image due to the interpolation inherent in zooming in and out.
Related
I have a chart that has strings for its x axis (a list of names). It's linked to a dynamic array, I have a problem where the graph resizes itself and squeezes 14-15 strings from the array and makes the bar chart small and tiny.
How can I achieve chunky bars and a scroll bar to scroll down to see the rest of the data even when new values are being added to the x-axis at runtime.
Have spent an hour searching with no help! =[
Edit:
Setting the PixelPointWidth Property to 300 gave me the width of the bar the way I want to be, but it has bunched the bars so that all the bars of the 4 series are overlapping instead of being side by side. WHere to go from here?
Edit2:
Manipulating the charts height is definitely getting the desired results, the only thing is the bigger the height, the more white space at the top of the chart, whats the fix for that,. and a fix for the Series representations to be "frozen" on scroll.
You can set the width of the chart every time you add new data to it:
Dim barWidth = Double.Parse(Chart1.Series(0)("PixelPointWidth"))
Chart1.Width = CInt(nData * barWidth) + 100
where nData is how many points there are and the 100 is some amount to take into account the space needed for the Y-axis labels and the legend.
Place the chart control in a Panel as suggested by jmcilhinney with AutoScroll set to true, and you will get a scrollbar when the width of the chart exceeds the width of the panel.
If you want the chart to show the latest added data, you can set the horizontal scroll position after setting the width of the chart:
Panel1.HorizontalScroll.Value = Panel1.HorizontalScroll.Maximum
I'm trying to scale a panel to fit it's parent panel, which I have accomplished By doing this:
ValSize = New Size(basePanel.Width - 20, basePanel.Height - 20)
This works well, but now I want to add another panel (dragItem) to this one I just scaled down (basePanel), but I need to keep the scaling the same between the 2 panels so they are not the same size but scaled the same mount. I was trying to use this formula to find how much I scaled the first item and get a percentage and use that for the new panel.
Dim scaleWidth As Double = Math.Abs(basePanel.Width - dragItem.Width) / dragItem.Width
Whats the proper way to do this?
If you want to get the ratio you are only supposed to divide.
Ratio of a smaller panel compared to the original:
Dim scaleWidth As Double = otherPanel.Width / basePanel.Width
Returns values <= 1
Ratio of the original panel compared to a smaller:
Dim scaleWidth As Double = basePanel.Width / otherPanel.Width
Returns values >= 1
So if you have a panel that is 200px wide and a smaller one that is 150px wide, the ratio will be 0.75. To create a new panel from this based on the smaller panel you would do:
Dim newWidth As Integer = scaleWidth * otherPanel.Width
Since scaleWidth is 0.75 and otherPanel.Width is 150, you will get the following result: 0.75 * 150 = 113 (112,5 to be exact, but it's rounded since it's an integer).
Now your third panel will be 25% smaller than the second panel. The second panel in turn is 25% smaller than the original panel.
Although it's possible, you don't need to do this calculations by yourself. Instead, set each panel's dock property to Fill and set the padding of the container as you like. In this case it's seems to want equal padding for every container.
I am developing an app that will show flags for countries some places, but after looking at flags I realized that the flags format was different for almost every country. Therefor I would like the height of the image view to automatically adjust it self to the width i set. Example:
Standard width for all flags: 100 px
USA : Height: 50px
UK: Height 56 px
Russia: Height 34px
I have no idea how to solve this, thanks for help! The best would be if this could be done automatically - without me needing to create example arrays or something for every flag to adjust size.
This is a ratio problem. Suppose your English flag is 120x80px. You want it to be 100px wide. How tall will it be? You have to scale the width and height by the same ratio.
First of all, calculate the ratio between the desired width of the flag and its actual width:
CGFloat ratio = 100.0f / 120.0f;
That gives us a ratio of 0.83. Now we can calculate the display height by multiplying the actual height by the ratio:
CGFloat height = 80.0f * 0.83;
The display height is 66.4px.
Here's the neat thing: UIImageView does this for you. If you specify the width of the image view and set its content mode to UIViewContentModeScaleAspectFit it does the hard work automatically.
See this question:
How to scale a UIImageView proportionally?
You could set the size of the image view from the size of the image as follows:
UIImage* flagImage = [UIImage imageNamed:"flagimage.png"];
CGRect flagImageRect = flagImageView.frame;
flagImageRect.size = flagImage.size;
flagImageView.frame = flagImageRect;
flagImageView.image = flagImage;
I guess you would do the above in a loop where you are setting the flag images for all your image views. You could also take the opportunity to scale your images (if desired).
I have create a Quartz composition for use in MAC OS program as part of my interface.
I am relying on the fact that when you have composition sprite movement (a text bullet point in my case) is limited both in the X plane and Y plane to minimum -1 and maximum +1.
When I scale up the window / make my window full screen, I find that the horizontal plane (X axis) remains the same, with -1 being my far left point and +1 being my far right point. However the vertical plane (Y axis) changes, in full screen mode it goes from -0.7 to +0.7.
This scaling is screwing with my calculations. Is there anyway to get the application to keep the scale as -1 to +1 for both horizontal and vertical planes? Or is there a way of determining the upper and lower limits?
Appreciate any help/pointers
Quartz Composer viewer Y limits are usually -0.75 -> 0.75 but it's only a matter of aspect ratio. X limits are allways -1 -> 1, Y ones are dependents on them.
You might want to assign dynamically customs width and heigth variables, capturing the context bounds size. For example :
double myWidth = context.bounds.size.width;
double myHeight = context.bounds.size.height;
Where "context" is your viewer context object.
If you're working directly with the QC viewer : you should use the Rendering Destination Dimensions patch that will give you the width and the height. Divide Height by 2, then multiply the result by -1 to have the other side.
I'm trying to pass an image showing to the user a countdown. For this, I'm using a separate thread where I'm checking when the countdown timer should be started, and when so, I draw an image for every 6 seconds passed.
What's annoying is when I pass the drawn image to the UI, the quality of the image is changed and it looks bad to the user.
This is my little script that handles the drawings:
Try
remainingTime = (#12:04:00 AM# - (DateTime.Now - local_DateTimeclick)).ToString("HH:mm:ss")
remainingTimeInSeconds = Convert.ToDateTime(remainingTime).Minute * 60 + Convert.ToDateTime(remainingTime).Second
If remainingTimeInSeconds Mod 6 = 0 Then
g.ResetTransform()
g.TranslateTransform(52, 52)
g.RotateTransform(230 - remainingTimeInSeconds / 6 * 9)
'g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
'g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
'g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
'g.CompositingMode = Drawing2D.CompositingMode.SourceCopy
'g.PixelOffsetMode = Drawing2D.PixelOffsetMode.
g.DrawImage(Tick, 10, 10)
End If
Catch
remainingTime = "Times Up"
End Try
In the above section,
- *local_DateTimeClick* is the variable that is set when the countdown should start
- Tick is a Bitmap that represents the image i have to draw for every 6 elipsed seconds
- g is a Graphics object from image that i return into the main window.
Also tried with changing the properties of g, but there was no positive effect.
Anyone have any idea what can i do to make this properly work without changing the quality of the returned image? Any tip/advice is welcomed.
Because Drawing2D.SmoothingMode only applies for 2D vector drawing methods such as Graphics.DrawEllipse and Graphics.DrawLine.
It doesn't affect drawing bitmaps with Graphics.DrawImage.
From the .NET documentation:
The smoothing mode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing).
You have two options at this point:
Pre-render every possible orientation of the image, and then just display different Image objects at each tick
use the .NET vector drawing methods to render your image instead of using a pre-rendered bitmap.
Without knowing the actual image you're transforming, I can't say which would be more appropriate.
from a graphic designer perspective followed at my company, i think your should crop your images to fit in the label:
1. it enhance performance by saving processing power.
2. it look better ?!.
regards