A Simple Number Countdown
Hello all.
This is my first time posting on the Adobe Forums, but I can tell you, this community has been a huge help over the years! I finally found a problem that I couldn't find the answer to by searching online, and I hope someone with some more AS2 knowledge than me can help me with it.
Basically, what I'm looking to do is have a count from one number to another number over the course of 20 or 30 frames. I guess that's not important.
The effect that I'm trying to achieve is this:
I have a map animation, that I need to start at a specified date. Let's say 1900, then cycle through to 2000, then 2050, then 2100.
So I have four stages of this movie.
I thought it would be easy to find something like this online, but I haven't found it anywhere. I was guessing it would have to be some kind of for loop, but to be honest, my knowledge of coding isn't that great, and it's not something I could write from scratch.
Does anyone have any links or references they could help me with? Maybe a nudge in the right direction? Am I completely wrong in assuming it would be a for loop?
I'd like the ability to change the dates somewhere, possibly a variable.
Has anyone seen something like this before?
Hi. Thanks for your quick reply.
Honestly, what I'm looking for is a dynamic text box, where I can change the font.
I'd like it to start at 1900, then cycle through the years until you get to 2000, then 2000 to 2050, then 2050 to 2100, within a certain number of frames. It could go every 2 or 3 years. It really doesn't matter. It's more for the effect than anything else.
This might help.
Here is a link to exactly what I have so far. http://ohmygraphics.com/clients/covalent/OCPR/ocpr_animation_working.html
You can hit "play" and "replay" once the movie is complete.
Eventually, I'm going to make it so you can hit "next" or "previous" and you'll see just that transition, and the dates w/ cycle through that particular stage.
I've basically just created keyframes w/ the years for now, but I would like that to be dynamic, because I'm having a hard time getting the dates to sync up with the movie.
What I was hoping would happen, is I could set the variables at the key frames, then have the AS figure out which years to display in between those dates, within the 30 frames.
The trouble with going by a set number of steps is that it doesn't cover the same amount of years for each stage. That's why I was hoping to do something with a loop of some sort and have it spit out the numbers in between based on some calculation of the amount of frames to fill.
Similar Messages
-
Creating a Simple Number Field
I want to basically create a JTextField only instead of text, numbers including decimals. I tried putting number into a text field but java won't see them as double. I tried the tutorial example with a formatted text field, however, they explain abstract and listeners for validating which I could care less about. I also tried the following code from the tutorial which doesn't work.
JFormattedTextField ftf = new JFormattedTextField();
ftf.setValue(new Number(100));
The compiler says Number cannot be instantiated as it is abstract. How can the tutorial do it? I have had the same problem with other examples in the tutorial such as the Border examples for creating compound borders. The examples don't work because the compiler says Border is not instantiable. It is frustrating. Any help with a simple number field for setting and getting the int or double values as numbers. Thanks.Read this section from the Swing tutorial. It does exactly what you want and provides code as well:
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html -
Hi,
I'm a newbie and looking to create a simple number counter (ie dates from 1900 to 2007 ticking over).
It's to be used on a history peice showing the progress of a company.
Doesn't need to be any special effects, just increasing numbers.
Cheers!Welcome to the discussions. Search is your friend:
http://discussions.apple.com/search.jspa?objID=f656&search=Go&q=counter
Patrick -
I am trying to create a simple program to input to real numbers and display the largest. This will then be used in a menu selection program that I am creating. I keep getting the error:
---------- Capture Output ----------
"C:\j2sdk1.4.2\bin\javac.exe" SmallestNumber.java
SmallestNumber.java:27: 'else' without 'if'
else
^
1 error
Terminated with exit code 1
But to me - the code looks correct. Can anyone pick up my error?
I am using the SavitchIn class from the book: "An introduction to computer science" by Walter Savitch
public class SmallestNumber {
public static void displayNumber() {
double num1 = 0;
double num2 = 0;
float average, count;
System.out.println("Plese enter a positive number:");
num1 = SavitchIn.readDouble();
System.out.println("Please enter a second postive number:");
num2 = SavitchIn.readDouble();
if (num1 > num2);
System.out.println ("The smallest number is: ");
System.out.println (num2);
else
if (num2 > num1);
System.out.println ("The smallest number is: ");
System.out.println (num1);
} //end main
} //end classI have tried including and removing brackets around both if statemetnts.
Any help would be appreciated.
Thankyou>
if (num1 > num2);
System.out.println ("The smallest number is:
ber is: ");
System.out.println (num2);
else
if (num2 > num1);
System.out.println ("The smallest number
lest number is: ");
System.out.println (num1);What do you mean "the code looks correct" to you????
You have a semicolon after the if statement. Also if you have more than one statement to execute for an "if" condition, you need to enclose them in brackets { and }
Here's the proper code:
if (num1 > num2) {
System.out.println ("The smallest number is: ");
System.out.println (num2);
} else if (num2 > num1) {
System.out.println ("The smallest number is: ");
System.out.println (num1);
} -
Reversable simple number encoding
It is simple to uniquely encode a number to another number within a certain "MAX", eg 2^31. Given to primes MULT and PLUS we can do it like this:
int encoded=(number*MULT+PLUS)%MAX;
eg for MAX=8, MULT=253, PLUS=13:
number encoded
0 5
1 2
2 7
3 4
4 1
5 6
6 3
7 0
All encoded numbers are unique.
My question is: How do I reverse this function? Eg in example given coded=7, I decode it to 2, knowing that MAX=8, MULT=253 and PLUS=13.
In answer to the commonly asked question "why do you want to do this?", it is just because I want to disperse an orderdered set {0,1,2,...} to a set of numbers that later can be reversed to the ordered set.
GilRE-POST, RE-POST, RE-POST, RE-POST, RE-POST:
The Forum didn't like my [...] with b in it, jsut became bold: Have [c] now instead!
Thanks all for your answers. Have got some good ideas but I'm not quite happy.
The mod operator is a one way operation. There is no way to undo it in constant time. You have to perform a search over the parameter space to find the result. (euclids is one such approach)
The easiest way of solving it is to store the original value. This is likely not possible in your case (judging from your previous posts about memory limitations).But since the values are mapped 1 to 1, it seems like there should be a reversed function. There is a determined answer for all values.
Another approach is to store the divisor. If you choose your MULT, PLUS and MAX values well the divisor can be stored in a single byte.I have such an solution. But then I get 2 numbers that "encode" the original number.
Pardon me if this should be obvious but why do you want to disperse an ordered set to a set of numbers that later can be reversed to the ordered set? It's not for decryption, just for dispersing or hashing.
A simpler hash would be to just XOR your number with an appropriatly large const. This does not give as good a distribution as themethod you suggested but may be sufficient.
Nah, it's not sufficient I think.
Extrapolate to XORing with a number of CONST values add in a few shifts so that the change of a single bit affects more then one bit in your result and you should get a reasonable pseudo random distribution. (MD5 checksum style).Should work, but I don't know how to do it.
The solutions to find the value by "finding" it by "testing" can work since MAX is rather small and the code is executed very seldomly at non-critical part of the program.
BUT, I found another interesting solution. I briefed my mathematics. It's the field of "limited bodies", or just a determined contious set Zn, {1,1,...,n-1}. The theory says: For the set Zn, there is an element [c], denoting the set of numbers that mod n are b, and an element [a] such that [a]*[c]=1, iff c is relatively prime to n. [a] is called the multiplicative inverse to [c]. The nice thing about a and c is that they give eachothers inverses in Zn.
Eg: n=11, a=5, c=9
value=0: 0 * 5 % 11 = 0 ; inverse: 0 * 9 % 11 = 0
value=1: 1 * 5 % 11 = 5 ; inverse: 5 * 9 % 11 = 1
value=2: 2 * 5 % 11 = 10; inverse: 10* 9 % 11 = 2
value=3: 3 * 5 % 11 = 4 ; inverse: 4 * 9 % 11 = 3
value=4: 4 * 5 % 11 = 9 ; inverse: 9 * 9 % 11 = 4
value=5: 5 * 5 % 11 = 3 ; inverse: 3 * 9 % 11 = 5
value=6: 6 * 5 % 11 = 8 ; inverse: 8 * 9 % 11 = 6
value=7: 7 * 5 % 11 = 2 ; inverse: 2 * 9 % 11 = 7
value=8: 8 * 5 % 11 = 7 ; inverse: 7 * 9 % 11 = 8
value=9: 9 * 5 % 11 = 1 ; inverse: 1 * 9 % 11 = 9
value=10:10* 5 % 11 = 6 ; inverse: 6 * 9 % 11 = 10
And we found a nice reverseable dispersing function! Could be combined with XOR too to give even more hash-like functionality!
A nice way to find n, a and c is to chose n and a to primes, a<n, and then finding c with help of Euclides.
Gil -
Film leader - number countdown - where can I find?
I thought it would be fun to add an "old fashioned" film leader to the start of a movie (the kind that runs at the very start of a REAL film, with the numbers that count down to 2). But I have NO idea where I can find one. I've only been able to find one professional stock footage place on the web, but I'd have to pay $600 to get this wee clip in a package with hundreds of others.
Is there somewhere that offers this kind of video clip for - ahem - free? Or is it even embedded somewhere as an effect in iMovie - that I'm missing?Gee Three (Slick Volume 5)has a nice countdown plugin..not free, but not $600 either;)
http://www.geethree.com/slick/V_05.html
Sue -
So Simple - Number next to my name?
In iCal we have 5 separate calendars. They're listed down the left-hand side of the screen. One of the calendars, mine, has the number 1 next to it. I can't figure out what it refers to or how to make it go away. Not crucial, just annoying. What am I missing? Is this an old alert I need to clear out?
THanks,
MAfter a little more searching I found the answer. See here:
http://discussions.apple.com/thread.jspa?messageID=8450045� -
Simple number question..
I need to use a float to look up information in an array (actually 2 floats to find info in a 2 dimensional array, but anyway). So basically i need to use the two integer values above and below. Mathematically this is usually refered to as the floor or ceiling of a value (ie the floor of 33.7 is 33 etc.) but i can't seem to find any suitable methods that will find this. I could cast to a float and do some comparisons to see if its been rounded down/up but i'll bet theres a better way, and speed is important here...
Can anyone point me in the direction of the correct method? Thanks.ah, knew they'd be there somewhere, thanks! And there was me looking in the Float docs... should have figured that out by myself really.
-
Need help with " Number guessing game " please?
This is what teacher requires us to do for this assignment:
Write a program that plays a simple number guessing game. In this game the user will think of a number and the program will do the guessing. After each guess from the program, the user will either indicate that the guess is correct (by typing �c�), or that the next guess should be higher (by typing �h�), or that it should be lower (by typing �l�). Here is a sample output for a game. In this particular game the user thinks of the number 30:
$java GuessingGameProgram
Guess a number between 0 and 100
Is it 50? (h/l/c): l
Is it 25? (h/l/c): h
Is it 37? (h/l/c): l
Is it 31? (h/l/c): l
Is it 28? (h/l/c): h
Is it 29? (h/l/c): h
Is it 30? (h/l/c): c
Thank you for playing.
$
This program is implementing a binary search algorithm, dividing the range of possible values in half with each guess. You can implement any algorithm that you want, but, all things being equal, binary search is the best algorithm.
Write the program so that the functionality is split between two classes: GuessingGameProgram, and NumberGuesser.
GuessingGameProgram will only be used for its main function. It should instantiate a NumberGuesser, and it will be responsible for the loop that notifies the user of the next guess, reads the �h�, �l�, or �c� from the user, and sends an appropriate message to the number guesser accordingly.
The guesses themselves should all be generated by the NumberGuesser class. Here is a diagram of the members and methods for the class. Notice that the members are unspecified. Feel free to give your NumberGuesser class any members (which we have also been calling fields, or instance variables) that you find useful. Make them all private.
NumberGuesser
NumberGuesser(int upperLimit, int lowerLimit)
int guess()
void higher()
void lower()
The constructor should take two integer arguments, a lower and upper bound for the guesses. In your program the constructor will be called with bounds of 0 and 100.
The guess method should return the same value if it is called more than once without intervening calls to the lower or higher methods. The class should only change its guess when it receives a message indicating that its next guess should be higher or lower.
Enjoy. Focus your attention on the NumberGuesser class. It is more interesting than the GuessingGameProgram class because it is a general-purpose class, potentially useful to anybody who is writing a number guessing game. Imagine, for instance, that a few weeks from now you are asked to write a number guessing game with a graphical Java Applet front end. If you NumberGuesser class is well written, you may be able to reuse it without any modifications.
I'm new to JAVA and I'm set with my 2nd homework where I'm so confused. I know how to do something of this source in C language, but I'm a bit confused with Java. This is the code me and my classmate worked on, I know it's not 100% of what teacher asked, but is there any way possibly you guys could help me? I wrote this program if the game is played less then 10 times, thought I would then re-create a program without it, but now I'm confused, and my class book has nothing about this :( and I'm so confused and lost, can you please help? And out teacher told us that it's due the end of this week :( wish I knew what to do. Thank you so so much.
Here's the code:
import java.text.*;
import java.io.*;
class GuessingGame
public static void main( String[] args ) throws IOException
BufferedReader stdin = new BufferedReader(new InputStreamReader( System.in ) );
int guess = 0, limit = 9, x = 0, n, a = 0 ;
double val = 0 ;
String inputData;
for ( x = 1; x <= 10; x++) //number of games played
System.out.println("round " + x + ":");
System.out.println(" ");
System.out.println("I am thinking of a number from 1 to 10. ");
System.out.println("You must guess what it is in three tries. ");
System.out.println("Enter a guess: ");
inputData = stdin.readLine();
guess = Integer.parseInt( inputData );
val = Math.random() * 10 % limit + 1; //max limit is set to 9
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(0); //format number of decimal places
String s = nf.format(val);
val = Integer.parseInt( s );
for ( n = 1; n <= 3; n++ ) //number of guess's made
if ( guess == val)
System.out.println("RIGHT!!"); //if guess is right
a = a + 1;
System.out.println("You have won " + a + " out of " + x + " rounds");
System.out.println(" ");
n = 3;
continue;
if (n == 3 && guess != val) //3 guesses and guess is wromg
System.out.println("wrong");
System.out.println("The correct number was " + val);
System.out.println("You have won " + a + " out of " + x + " rounds");
System.out.println(" ");
continue;
//how close guess is to value
if ( guess == val - 1 || val + 1 == guess) //Within 1
System.out.println("hot");
else if ( guess == val - 2 || val + 2 == guess) // Within 2
System.out.println("warm");
else
System.out.println("cold"); // Greater than 3
inputData = stdin.readLine();
guess = Integer.parseInt( inputData );
//ratings
if ( a <= 7)
System.out.println("Your rating is: imbecile.");
else if ( a <= 8)
System.out.println("Your rating is: getting better but, dumb.");
else if (a <= 9)
System.out.println("Your rating is: high school grad.");
else if ( a == 10)
System.out.println("Your rating is: College Grad.!!!");Try this.
By saying that, I expect you ,and your classmate(s), to study this example and then write your own. Hand it in as-is and you'll be rumbled as a homework-cheat in about 20ms ;)
When you have an attempt where you can explain, without refering to notes, every single line, you've cracked it.
Also (hint) comment your version well so your tutor is left with the impression you know what you're doing.
In addition (huge hint) do not leave the static inner class 'NumberGuesser' where it is. Read your course notes and find out where distinct classes should go.
BTW - Ever wonder if course tutors scan this forum for students looking for help and/or cheating?
It's a double edged sword for you newbies. If you ask a sensible, well researched question, get helpful answers and apply them to your coursework, IMHO you should get credit for doing that.
On the other hand, if you simply post your assignment and sit there hoping some sucker like me will do it for you, you should be taken aside and given a good kicking - or whatever modern educational establishments consider appropriate abmonishment ;)
I'd say this posting is, currently, slap bang between the two extreemes, so impress us. Post your solution in the form you intend to hand it in, and have us comment on it.
Good luck!
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class GuessingGame
public static void main(String[] args)
throws Exception
BufferedReader reader= new BufferedReader(
new InputStreamReader(System.in));
NumberGuesser guesser= new NumberGuesser(0, 100);
System.out.println(
"\nThink of a number between 0 and 100, oh wise one...");
int guess= 0;
while (true) {
guess= guesser.guess();
System.out.print("\nIs it " +guesser.guess() +"? (h/l/c) ");
String line= reader.readLine();
if (line == null) {
System.out.println(
"\n\nLeaving? So soon? But we didn't finish the game!");
break;
if (line.length() < 1) {
System.out.println("\nPress a key, you muppet!");
continue;
switch (line.toLowerCase().charAt(0)) {
case 'h':
guesser.higher();
break;
case 'l':
guesser.lower();
break;
case 'c':
System.out.println("\nThank you for playing.");
System.exit(0);
default:
System.out.println(
"\nHow hard can it be? Just press 'h' 'l' or 'c', ok?");
continue;
if (guess == guesser.guess()) {
System.out.println(
"\nIf you're going to cheat, I'm not playing!");
break;
private static class NumberGuesser
private int mLower;
private int mUpper;
private int mGuess;
NumberGuesser(int lowerLimit, int upperLimit)
mLower= lowerLimit;
mUpper= upperLimit;
makeGuess();
private void makeGuess() {
mGuess= mLower + ((mUpper - mLower) / 2);
int guess() {
return mGuess;
void higher()
mLower= mGuess;
makeGuess();
void lower()
mUpper= mGuess;
makeGuess();
} -
Month/Year reverse countdown help needed
I need to create a simple reverse countdown that only needs
the detail level of Months and Years. All of the tutorials I've
found online are for counting down smaller intervals of time, like
days, minutes, seconds, and milliseconds.
I'm not very experienced with the code needed for such a
timer, but essentially what I would like to have happen is:
1. The current Month and Year are displayed onscreen.
2. I click the mouse, and the Month and Year begin to count
BACKWARDS, as if going back in time, so the Year would go from
2007, to 2006, to 2005, etc, while the 12 months of the year would
count down in reverse to coincide with the Year.
3. When I click the mouse again, the countdown stops at
whatever month/year it happens to be, I assume all the way back to
the Year 0 if I let it play to the end.
BONUS points if this reverse countdown could speed up over
time, so that it appears to begin slowly, and rapidly speed up as
the timer goes further back in time.
Note that I do not need to use the ACTUAL date taken from the
computer's clock, I'd be happy to just enter in, say "June 2007" as
the start date and have it reverse from there. So even something
that would just countdown from the numeral "2007" to "0" while a
movieclip of the 12 months cycling along could work, though I have
no concept as to how to control/increase the speed of such an
animation as it plays.put the months in an array "december" to "january", and set a
variable equal to the start year and an index that corresponds to
the start month. display the start year/month.
start a loop (setTimout would work) with a variable call
frequency that calls a function that
1. increases your array index (decreasing the year and
restarting your index at 0 after the last array element is
displayed) and displays the updated month/year
2. decreases the variable call frequency and define another
setTimeout. -
Does anyone know how to get or create the image of the clock counting down to the start of a movie that has the director credit etc? Usually white text on black...
TimYou can find them on google. Or make your own in motion/Photoshop/AE etc.
Here's a link to a simple motion countdown clock
http://idustrialrevolution.com/component/option,com_sobi2/sobi2Task,sobi2Details /catid,2/sobi2Id,8/ -
Very, very rusty...simple comparison
I'm creating what I thought would be a simple number-picking
app.
Four text members filled with random(50)...I don't want
duplicate numbers, so I have tried every which way of writing this
code that I can think of, but nothing is working for me. I haven't
used Director in a long while and my Lingo skills have dulled
significantly. If anyone wants to see my latest version of my
crappy, verbose script, here is a smaple of one of four handlers I
was experimenting with:
on compareResult4
if member ("result4").text = member ("result3").text then
put random(50) into member"result4"
go to the frame
if member ("result4").text = member ("result2").text then
put random(50) into member"result4"
go to the frame
if member ("result4").text = member ("result1").text then
put random(50) into member"result4"
go to the frame
else
if member ("result4").text <> member ("result1").text
then
nothing
if member ("result4").text <> member ("result2").text
then
nothing
if member ("result4").text <> member ("result3").text
then
nothing
end if
end if
end if
end if
end if
end if
end
Any ideas, thoughts or suggestions welcome!!!
Thanks in advance!
MSTry putting this on each of the 4 sprites. I assume the
members are
named "result1", "result2", etc. Also, watch for line
wraps... this
should be exactly 23 lines of text.
on beginSprite me
me.getRandom()
repeat while true
num=1
repeat with i=1 to 4
if
sprite(me.spriteNum).member.name.char[sprite(me.spriteNum).member.name.char.count]=i
then next repeat
if
sprite(me.spriteNum).member.text=member("result"&i).text then
me.getRandom()
next repeat
else
num=num+1
end if
if num=4 then pass
end repeat
end repeat
end
on getRandom me
sprite(me.spriteNum).member.text=string(random(50))
end -
Lack of customer service/Liars
I went into a verizon store wanting to add a new line. Everything seemed to go smoothly. He asked if I wanted the 5S or 5C. I decided to go with the 5C. I paid my $145 and he helped me pick out a number. He said to come back at the end of the week to swap numbers on the phone. I went in on that Friday and the girl told me that I had to buy 2 sim cards. I wasn't advised of this. Had to pay $20. I left.
Later in the week I start getting text messages saying I am over my data usage. All of the phones start doing it. I up it for $10 not understanding really what was up. They kept coming. Over and over. I call customer service, go over my phones. Ends up the guy changed my calling plan without me knowing. I had unlimited data but gone and he backdated it. They can only switch you back within 14 days. By backdating he screwed that up. The lady apologizes and promises she will follow up the next day I go to Verizon because I am fed up. I explained how he screwed everything up. They put me on phone with customer service who again apologizes profusely and said she has filed claims and someone will contact me within 24 hours.I am so frustrated I tell her to take the phone back it isn't worth it. Sure if I pay $75. What? I was never told that. He told me I had 14 days to change my mind. He didn't mention that. He also didn't mention that they were adding $40 on my bill. I thought it was $10. He never mentioned that I didn't have to get that phone. He didn't mention the differences.. He didn't mention anything. I have NOT heard from anyone and I am still getting usage notices. They have done nothing. I called back and left a message to have the girl I originally talked to call me back. No one has called. I am completely disgusted and one step away from posting this everywhere.The reason you received the worst customer service - is because Verizon seems to have spent decades to develop the worst customer service program imaginable, and has searched the world over to hire the most incredibly incompetent people to staff their management, employees, phones lines, and stores to overshadow anyone who actually was mistakenly hired who is professional. I also happen to need help if you could assist, I need to go back to the store where I bought my 5s to find the store manager who can not seem to call me back after hours spent trying to get a hold of him, and help me stuff this phone up where the sun doesn't shine...
When I got home with my new 5s, I found their was no quick start guide, no recipe, no explanation of plan and absolutely no resolution after many calls I made - to try to clear up my charges. I was charged almost $750.00 on my first bill, and it was due immediately. I had set-up a pro-rated account, and was told my costs were supposed to be around $450.00 for everything, and my bill would be around $91.00 - they are charging me around $750.00 and around $140 a month - $50.00 higher... I called customer service, and the store several times since then. I was told many times to go online to resolve my problems. (ha! - a good one).... This is because you can not get a phone call answered due to the astounding amount of customer complaints and problems Verizon has managed to incur.
I happen to have an attorney on hand, and told him I am going back to the Verizon store and cancelling my account due to breach of contract. He said to let him know if they refuse... He was also a Verizon customer and cancelled his account... ironic... He informed me I was promised quality customer care, and I did not receive all of my product on purchase - namely a quick-start guide... Funny a 50 cent book will cause Verizon to lose thousands...
Verizon simply put, has a non-existent customer support network - the worst I have seen... You have to navigate through pages of online crap to get a simple number... If Verizon stood behind its service, it would have the customer service number listed and prominently displayed as well as provide product guides - instead of telling customers to find help online from others...
I am really surprised Verizon is a big sham and hides its shady organization behind smoke and mirrors disguised as too much worthless information posted - just look at all the crap below this page... Especially note the 8 links for Service and Support does not include any actual customer service assistance regarding account problems. I was told to go back to my
Verizon store to discuss my problems - it is 1.5 hours away.... -
Overriding DPI of images when displaying them in WPF
Posting following because it might help someone else. It took me quite
while to figure this one out.
I started learning C# and WPF recently. I hadn't had so much fun since the
late 1990s when I learned Java.
But I stumbled on one major irritant working on my project, a picture viewer.
Contrary to just about every environment I've encountered, WPF insists on
taking the DPI of images into consideration when displaying them. What I want
is to display the images in some area of my app, pixel-for-pixel unless that
results in the picture going beyond the frame, in which case the image
needs to be scaled down so it fits. I don't want to have a larger image because
the DPI is smaller than 96, and I don't want a smaller image because the DPI
is higher than 96.
As far as I'm concerned, DPI is more often than not a useless number. Two
examples.
1) My camera arbitrarily assigns a DPI value of 72 to all pictures it takes.
But what "inches" are we talking about here? Obviously there is no answer
to that question. So it's a meaningless number.
2) If I scan a 35 mm color slide, I will probably do so at a DPI value of
something like 2400, but I'd sure want to display the resulting image much
larger. By default, WPF will show it at original size, totally useless.
The DPI here is certainly meaningful, but not as a display parameter!
I compared two images from same original (leware.net/photo/dpi.html),
one resized to a DPI of 48, the other to a DPI of 192. In a hex editor,
except for the one byte that encodes the DPI value, the two files are
identical. It's the same image, with a different DPI value, but no other
differences.
So how do I get a WPF picture viewer to display images without taking their
DPI into consideration? As every browser and viewer I know will do?
At first, I thought that I would be able to do something like:
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri(somePathOrUrl);
img.DpiX = 96.0; // override
img.DpiY = 96.0;
img.EndInit();
But DpiX and DpiY are "get" only, not "set". Yet, it's just a simple number,
and changing it before WPF does anything with the image does not sound like a
big challenge (even when waiting for DownloadCompleted event). It's almost as
if the WPF designers decided that WPI was sooo important that they would never
allow anyone to modify the value...
The first approach I tried used RenderTargetBitmap (created at 96 DPI),
DrawingVisual, DrawingContext classes. Seems quite complex. It worked, but
I wouldn't call it elegant.
After much browsing (and with improving understanding), I found a better approach.
In simple terms, I set the Image's Width and Height to PixelWidth and PixelHeight
(which essentially makes the resulting DPI to be 96), and I set the Image's
MaxWidth and MaxHeight to the space available to the Image in the app, to force
scaling if the source is too large. I used Stretch=Uniform. Code fragments below.
The Image is placed in a UniformGrid container which provides the MaxWidth and
MaxHeight, and which centers the Image inside.
This approach is quite a bit more elegant, it removed nearly 100 lines of code
from the app. I still think though that it's not as simple as it could be.
I had also read about "DPI awareness", didn't really understand it, but it seems
to deal with DPI of display device, not of source images.
So two questions:
1) Is there a even easier way, esp. a way to directly modify or ignore an image's
DPI values before using it (without copying the image into some new bitmap)?
2) Barring that, is there something simpler than above?
Note that I'm fine with the application being otherwise DPI aware (fonts,
buttons, &c).
Thanks
WPF code fragments of the trivial application I used to fine-tune the second
approach. The two images are 160x100 pixels (but any pair of images smaller
than the display will do the trick), one at DPI 48, one at DPI 192, and named
IMG_6726s48.jpg and IMG_6726s192.jpg. The both show at the same size, as I
wanted.
To see the original problem as I experienced it, set Stretch=None and comment
out the two pairs of lines that set image.Width and image.Height.
XAML
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="512" Width="512">
<Grid>
<TextBlock Name="lpvMessage" Text="(messages)" Margin="2,2,10,0" VerticalAlignment="Top" TextWrapping="NoWrap"/>
<UniformGrid Name="grid" Margin="48,48,16,16" Background="LightGray" SizeChanged="gridSizeChanges">
<Image Name="image" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" MouseDown="onClickInImage"/>
</UniformGrid>
<Button Content="48" HorizontalAlignment="Left" Margin="10,68,0,0" VerticalAlignment="Top" Width="32" Click="buttonClick"/>
<Button Content="192" HorizontalAlignment="Left" Margin="11,93,0,0" VerticalAlignment="Top" Width="32" Click="buttonClick"/>
</Grid>
</Window>
XAML.CS
namespace WpfApplication1
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
grid.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xF0, 0xF0, 0xF0)); // shows grid for testing
changeImage("48");
private void changeImage(string dpi)
BitmapImage img = new BitmapImage();
img.BeginInit();
img.UriSource = new Uri("R:/IMG_6726s" + dpi + ".jpg"); // IMG_6726s48.jpg or IMG_6726s192.jpg.
img.EndInit();
image.Source = img;
lpvMessage.Text = "Loading :/IMG_6726s" + dpi + ".jpg";
private void onClickInImage(object sender, MouseButtonEventArgs e)
BitmapImage isrc = image.Source as BitmapImage;
image.Width = isrc.PixelWidth; // "ignores" DPI
image.Height = isrc.PixelHeight;
image.MaxWidth = grid.ActualWidth; // prevents scaling larger than 1:1
image.MaxHeight = grid.ActualHeight;
bool shifted = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift);
if (shifted) // shift-click to toggle Stretch between Uniform and None
if (image.Stretch == Stretch.None) image.Stretch = Stretch.Uniform;
else
image.Stretch = Stretch.None;
lpvMessage.Text = "grid.ActualSize=" + grid.ActualWidth + "x" + grid.ActualHeight +
" image.ActualSize=" + image.ActualWidth + "x" + image.ActualHeight +
" isrc.PixelSize=" + isrc.PixelWidth + "x" + isrc.PixelHeight +
" image.Stretch->" + ((image.Stretch == Stretch.None) ? "None" : "Uniform");
private void gridSizeChanges(object sender, SizeChangedEventArgs e)
BitmapImage isrc = image.Source as BitmapImage;
image.Width = isrc.PixelWidth; // "ignores" DPI (redundant here
image.Height = isrc.PixelHeight;
image.MaxWidth = grid.ActualWidth; // prevents scaling to larger than 1:1
image.MaxHeight = grid.ActualHeight;
lpvMessage.Text = "grid.ActualSize=" + grid.ActualWidth + "x" + grid.ActualHeight +
" image.ActualSize=" + image.ActualWidth + "x" + image.ActualHeight +
" isrc.PixelSize=" + isrc.PixelWidth + "x" + isrc.PixelHeight +
" image.Stretch->" + ((image.Stretch == Stretch.None) ? "None" : "Uniform");
private void buttonClick(object sender, RoutedEventArgs e)
Button b = sender as Button;
string dpi = b.Content as string;
changeImage(dpi);Being able to ignore DPI is all I'm asking for, and what I've always done for decades
If the objective is to fill the Window, then yes, it's simple, as the following example of a thumbnail image shows:
<Grid>
<Image Source="http://leware.net/temper/42fp.jpg"/>
</Grid>
Result below. DPI doesn't matter, pixel sizes don't matter, the source fills the Image control, while respecting the proportions.
But I don't want the image to fill the space available if it doesn't have enough pixels, it looks fuzzy and I don't like that.
So I add Stretch=None to the Image control, and it solves my problem, the image is shown at a size that corresponds to its pixel size (63x87), centered.
<Grid>
<Image Source="http://leware.net/temper/42fp.jpg" Stretch="None"/>
</Grid>
The above two XAML fragments give the following results:
The second is what I want. So Stretch=None, unless the image is larger than display area, in which case Stretch=Uniform.
Now I try my two test images, also with Stretch=None because they are smaller than display area.
These two images are both 160x100 pixels, and, when compared in a hex editor, differ
only in the couple of bytes that store the DPI value (0x0030 vs 0x00c0),
all the rest is the same.
<Grid>
<Image Source="http://leware.net/photo/IMG_6726s48.jpg" Stretch="None"/>
</Grid>
and
<Grid>
<Image Source="http://leware.net/photo/IMG_6726s192.jpg" Stretch="None"/>
</Grid>
Here's what I see:
DPI obviously does matter here, much to my surprise. WPF's behavior was unexpected. That was my original problem.
The DPI 48 image is enlarged by a factor of 2, the 192 DPI image is reduced by a factor of 2. What I want is in between, and the same for both images, a display based only on pixel sizes, like most browsers and picture viewers do.
In other words, I want one image pixel to be one display pixel, downsized to fit if the image is too large, but never enlarged beyond 1:1 to fill the available space.
I had a hard time figuring out how to get those two small images to show identically.
I finally got what I wanted with the solution at the top of this thread (overriding size of Image control instead of DPI). I'm sharing because it might help someone else.
Is there a better way to handle this when the DPI is arbitrary? Isn't there a way to just tell WPF to ignore images' DPI values or simply override it (force an image's DPI to 96)?
Quite possibly I'm trying to do something which does not quite fit in the philosophy of WPF. Maybe I'm closer now, I'm still learning (this discussion is helping).
I won't be surprised if my application misbehaves when the DPI of the display is not 96. Not a concern for now. -
Migrating E&M immediate start from 2821 VGW to AS5350XM but problems with signalling
Hi,
We currently have 2821 VGW platforms running E&M Immediate start. The T1s go into the DACS and the IP interface connects to the SIP server with a simple number plan.
So, when a T1 DS0 signals, the VGW talks to the SIP server, the SIP server does a database lookup and talks back to the VGW and passes the connection details.
However we are now migrating to the AS5350XM platform and replicating the config from the 2821 to the AS5350XM is causing signalling issues.
Here is a sample of the existing 2821 config:
voice rtp send-recv
voice service pots
voice service voip
sip
bind control source-interface GigabitEthernet0/0
bind media source-interface GigabitEthernet0/0
rel1xx disable
min-se 1700
voice class codec 1
codec preference 1 g711ulaw
codec preference 2 g729r8
controller T1 1/0
ds0-group 0 timeslots 1 type e&m-immediate-start
ds0-group 1 timeslots 2 type e&m-immediate-start
ds0-group 2 timeslots 3 type e&m-immediate-start
voice-port 1/0:0
define Tx-bits idle 1111
define Tx-bits seize 0000
define Rx-bits idle 1111
define Rx-bits seize 0000
timeouts wait-release 1
connection plar 1000
voice-port 1/0:1
define Tx-bits idle 1111
define Tx-bits seize 0000
define Rx-bits idle 1111
define Rx-bits seize 0000
timeouts wait-release 1
connection plar 1001
voice-port 1/0:2
define Tx-bits idle 1111
define Tx-bits seize 0000
define Rx-bits idle 1111
define Rx-bits seize 0000
timeouts wait-release 1
connection plar 1002
dial-peer voice 1000 pots
destination-pattern 1000
port 1/0:0
dial-peer voice 1001 pots
destination-pattern 1001
port 1/0:1
dial-peer voice 1002 pots
destination-pattern 1002
port 1/0:2
dial-peer voice 1 voip
preference 1
destination-pattern .T
session protocol sipv2
session target ipv4:192.168.150.2:5060
session transport udp
voice-class codec 1
voice-class sip options-keepalive retry 1
sip-ua
retry invite 2
timers trying 150
sip-server ipv4:192.168.150.2:5060
Here is the same on on the AS5350xm:
voice rtp send-recv
voice service pots
voice service voip
sip
bind control source-interface GigabitEthernet0/0
bind media source-interface GigabitEthernet0/0
rel1xx disable
min-se 1700 session-expires 1700
voice class codec 1
codec preference 1 g711ulaw
codec preference 2 g729r8
controller T1 3/0:1
framing ESF
ds0-group 0 timeslots 1 type e&m-immediate-start
ds0-group 1 timeslots 2 type e&m-immediate-start
ds0-group 2 timeslots 3 type e&m-immediate-start
cas-custom 0
define-abcd loop-open 1 1 1 1
define-abcd loop-closure 0 0 0 0
cas-custom 1
define-abcd loop-open 1 1 1 1
define-abcd loop-closure 0 0 0 0
cas-custom 2
define-abcd loop-open 1 1 1 1
define-abcd loop-closure 0 0 0 0
voice-port 3/0:1:0
timeouts wait-release 1
connection plar 1000
voice-port 3/0:1:1
timeouts wait-release 1
connection plar 1001
voice-port 3/0:1:2
timeouts wait-release 1
connection plar 1002
dial-peer voice 1000 pots
destination-pattern 1000
port 3/0:1:0
dial-peer voice 1001 pots
destination-pattern 1001
port 3/0:1:1
dial-peer voice 1002 pots
destination-pattern 1002
port 3/0:1:2
dial-peer voice 1 voip
preference 1
destination-pattern .T
session protocol sipv2
session target ipv4:192.168.150.2:5060
session transport udp
voice-class codec 1
voice-class sip options-keepalive retry 1
sip-ua
retry invite 2
timers trying 150
sip-server ipv4:192.168.150.2:5060
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
What I did notice was the following:
1) When defining loop open and loop closed custom bit configuration is different....on the 2821 you do it on the voice port. On the AS5350, it is not supported on the voice port but appears to be configurable via the T1 controller. I'm not sure if the AS5350 needs any further E&M signalling configuration as the problem lies in the signalling....the AS5350 when the line is cleared down appears to start ringing it again and not following the signalling pattern.
2) When doing a "show voice port" on the AS5350XM does not show E&M signalling, whereas it does on the 2821:
AS5350XM:
5350VGW#sh voice port
DS0 Group 3/0:1:0 - 3/0:1:0
Type of VoicePort is CAS
Operation State is DORMANT
Administrative State is UP
No Interface Down Failure
Description is not set
Noise Regeneration is enabled
Non Linear Processing is enabled
Non Linear Mute is disabled
Non Linear Threshold is -21 dB
Music On Hold Threshold is Set to -38 dBm
In Gain is Set to 0 dB
Out Attenuation is Set to 0 dB
Echo Cancellation is enabled
Echo Cancellation NLP mute is disabled
Echo Cancellation NLP threshold is -21 dB
Echo Cancel Coverage is set to 128 ms
Echo Cancel worst case ERL is set to 6 dB
Playout-delay Mode is set to adaptive
Playout-delay Nominal is set to 60 ms
Playout-delay Maximum is set to 1000 ms
Playout-delay Minimum mode is set to default, value 40 ms
Playout-delay Fax is set to 300 ms
Connection Mode is plar
Connection Number is 1000
Initial Time Out is set to 15 s
Interdigit Time Out is set to 10 s
Call Disconnect Time Out is set to 60 s
Ringing Time Out is set to 180 s
Wait Release Time Out is set to 1 s
Spe country is not configured
Region Tone is set for US
Station name None, Station number None
Translation profile (Incoming):
Translation profile (Outgoing):
lpcor (Incoming):
lpcor (Outgoing):
DS0 channel specific status info:
IN OUT
PORT CH SIG-TYPE OPER STATUS STATUS TIP RING
=============== == ============ ==== ====== ====== === ====
2821:
2821VGW#sh voice port
recEive and transMit Slot is 0, Subslot is 0, Sub-unit is 0, Port is 0
Type of VoicePort is E&M
Operation State is DORMANT
Administrative State is UP
No Interface Down Failure
Description is not set
Noise Regeneration is enabled
Non Linear Processing is enabled
Non Linear Mute is disabled
Non Linear Threshold is -21 dB
Music On Hold Threshold is Set to -38 dBm
In Gain is Set to 0 dB
Out Attenuation is Set to 0 dB
Echo Cancellation is enabled
Echo Cancellation NLP mute is disabled
Echo Cancellation NLP threshold is -21 dB
Echo Cancel Coverage is set to 128 ms
Echo Cancel worst case ERL is set to 6 dB
Playout-delay Mode is set to adaptive
Playout-delay Nominal is set to 60 ms
Playout-delay Maximum is set to 1000 ms
Playout-delay Minimum mode is set to default, value 40 ms
Playout-delay Fax is set to 300 ms
Connection Mode is plar
Connection Number is 1000
Initial Time Out is set to 15 s
Interdigit Time Out is set to 10 s
Call Disconnect Time Out is set to 60 s
Ringing Time Out is set to 180 s
Wait Release Time Out is set to 1 s
Companding Type is u-law
Rx A bit no conditioning set
Rx B bit no conditioning set
Rx C bit no conditioning set
Rx D bit no conditioning set
Tx A bit no conditioning set
Tx B bit no conditioning set
Tx C bit no conditioning set
Tx D bit no conditioning set
Rx Seize ABCD bits = 0000 Custom pattern
Rx Idle ABCD bits = 1111 Custom pattern
Tx Seize ABCD bits = 0000 Custom pattern
Tx Idle ABCD bits = 1111 Custom pattern
Ignored Rx ABCD bits = BCD
Region Tone is set for US
Analog Info Follows:
Currently processing none
Maintenance Mode Set to None (not in mtc mode)
Number of signaling protocol errors are 0
Station name None, Station number None
Translation profile (Incoming):
Translation profile (Outgoing):
lpcor (Incoming):
lpcor (Outgoing):
Voice card specific Info Follows:
Operation Type is 2-wire
E&M Type is 1
Signal Type is immediate
Dial Out Type is dtmf
In Seizure is inactive
Out Seizure is inactive
Digit Duration Timing is set to 100 ms
InterDigit Duration Timing is set to 100 ms
Pulse Rate Timing is set to 10 pulses/second
InterDigit Pulse Duration Timing is set to 750 ms
Clear Wait Duration Timing is set to 400 ms
Wink Wait Duration Timing is set to 200 ms
Wait Wink Duration Timing is set to 550 ms
Wink Duration Timing is set to 200 ms
Minimum received Wink Duration Timing is set to 140 ms
Maximun received Wink Duration Timing is set to 290 ms
Minimum seizure Timing is set to 50 ms
Delay Start Timing is set to 300 ms
Delay Duration Timing is set to 2000 ms
Dial Pulse Min. Delay is set to 140 ms
Percent Break of Pulse is 60 percent
Auto Cut-through is disabled
Dialout Delay is 300 ms
Hookflash-in Timing is set to 480 ms
Hookflash-out Timing is set to 400 ms
DS0 channel specific status info:
IN OUT
PORT CH SIG-TYPE OPER STATUS STATUS TIP RING
=============== == ============ ==== ====== ====== === ====
0/0/0:0 01 e&m-imd dorm idle idle
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Can anyone advise if further configuration is required on the AS5350XM in order to pass the E&M signalling correctly ?Well for me the forms were ok to open with 11g, just had to correct differences and recompile to run.
That there script is a ton of help!..well you forgot to mention the Output_File parameter, but I could find that myself now that I knew what to look at. Now if I could also set it not to produce .err files when everything went fine and to set the output names so that the old compiled forms get overwritten..
the SRW.* calls turned out to be things used in Reports, so it was hopeless to compile in forms..but also not needed
as for ENABLE_ITEM and DISABLE_ITEM I found these to use as their definitions in a library, that proved sufficient.
procedure enable_item
( p_menuName in varchar2
, p_menuItemName in varchar2
) is
v_menuItem menuitem;
begin
v_menuItem := find_menu_item(p_menuName||'.'||
p_menuItemName);
if (not id_null(v_menuItem))
and (get_menu_item_property(v_menuItem,visible) = 'TRUE')
then
set_menu_item_property(v_menuItem, enabled, property_true);
end if;
end;
procedure disable_item
( p_menuName in varchar2
, p_menuItemName in varchar2
) is
v_menuItem menuitem;
begin
v_menuItem := find_menu_item(p_menuName||'.'||
p_menuItemName);
if (not id_null(v_menuItem))
and (get_menu_item_property(v_menuItem,visible) = 'TRUE')
then
set_menu_item_property(v_menuItem, enabled, property_false);
end if;
end;Some forms still playing with me, but the compilation issues there don't seem to be connected with this topic..and now I got issues with reports >.< but that requires a topic elsewhere. Thanks all!
Maybe you are looking for
-
Dual display for mac mini?
Hi I need to display a wide quicktime movie across two matching 1920 x 1080 screens. I'd rather use a mini than 2 usb players and a sync board. Will this work? I think that the mini has one output that is HDMI, and the other DVI (?) How can I ensure
-
Changing screen resolution by zapping pram
Hi I persuaded a friend to go down the mac route. He now has a 2006 mac pro running Lion. When he boots up he sees the apple and the little counter thing, whatever it's called, and then the screen goes blank and his monitor tells him that there is no
-
Pb communication TCP/IP avec un oscillo Lecroy 6100 et librairie Visa
Hello, I am trying to communicate with a remote Lecroy 6100 scope through TCP/IP, using the visa library. I have configured my device with MAX but it can not open an INSTR session. I have check the IP address, my device respond to a ping. I have inst
-
Progress bar Fl cs3 as3.0
below is my very simple code to load images from a instance of button component into an instance of UIloader component. there are multiple buttons like this one i can't get it... the way to get progress bar to listen and respond to the loading of the
-
try to update my mac and iphone apps but there is massage erre , you cannot update this software since you have not owned the major version of this software,