Using double/floats for co ordinates?

hi is it possible to use float/double values for the following code or simlar?
g.drawImage(cards, 0.5, 0.8, this);
does the drawimage on support ints?

Update and demo: Am I the only one who is forever tweaking rendering hints
to get the right effect? Anyhowdy, I think INTERPOLATION was the hint I needed
to tweak to get subpixel shifting of images:
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
public class ShiftyExample extends JPanel {
    private BufferedImage image;
    private float delta;
    public ShiftyExample(BufferedImage image, float delta) {
        this.image = image;
        this.delta = delta;
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2.drawRenderedImage(image, null);
        g2.drawRenderedImage(image, AffineTransform.getTranslateInstance(delta, 0));
        g2.dispose();
    public static void main(String[] args) {
        EventQueue.invokeLater(new GuiBuilder());
    static class GuiBuilder implements Runnable {
        public void run() {
            BufferedImage image = createImage();
            JPanel cp = new JPanel(new GridLayout(1,0));
            cp.add(new ShiftyExample(image, 0f));
            cp.add(new ShiftyExample(image, 0.5f));
            cp.add(new ShiftyExample(image, 1f));
            cp.add(new ShiftyExample(image, 1.5f));
            cp.add(new ShiftyExample(image, 2f));
            JFrame f = new JFrame("ShiftyExample");
            f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(300,200);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        BufferedImage createImage() {
            BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = image.createGraphics();
            g.setColor(Color.BLACK);
            g.drawLine(10,0,10,100);
            g.dispose();
            return image;
}Explanation: the image is a vertical black line on a clear background.
What you see on the frame are five versions of the image displayed
against a shifted copy of itself, shift 0, 0.5, 1, 1.5 and 2 units. If you really stare at the
fractional examples, you will see gray pixels being used instead of just black
and white. Woop-de-doo...

Similar Messages

  • A problem using doubles/floats

    i have an applet with 4 radio buttons and 5 check boxes! when i click on some (mix and match) the value on the text field sometimes goes like this 8.8888889 etc, and other times it is like 2.34! how can i change that 8.88889 to be displayed as 2.34! i have tried changing the value in the code, but that solves the problem but then a diff combination does the same thing! :(

    But anyway, since we're in this thread now...
    The short version is that there are a finite number of values that can be stored in a float or double, but there are infinitely many float/double values in the real numbers in the range between he min value and max value. So a lot of numbers are going to be aproximations.
    Why is a "simple" number like, say, 0.9, not exact, you ask? Java's VM (and pretty much all modern computer hardware) stores floating point number in base-2, not base ten. So if you look at the bits, and you see "1" in the first position after where the binary-point (base-2 equivalent of a decimal point) would be, that doesn't mean 1/10, it means1/2. So "0.5" in decimal (base-10) is the same as "0.1" in binary (base-2). What's "0.1" base-10 in base-2? Don't know off the top of my head, but it's a repeating fraction, just like 0.3333333... for 1/3 (which, in base-3, is 0.1, exactly).
    For more details, see:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

  • Conky won't use double buffer anymore?

    i posted the other day having issues setting up dual monitors, not that i got any help, but figured i'd mention. anyway, since i've had the dual monitors setup, conky won't run using double buffering for some reason. its in my conky config, and DBE is being loaded in my xorg.conf. so its bugging me now. wondering is anyone has a clue here. my system is fully up to date as of right now, and running an nvidia card, so nvidia driver on a 7900GS video card, might be an 8800, i forget which card is in which box at the moment
    here's my conky config
    alignment top_right
    background yes
    border_width 1
    cpu_avg_samples 2
    default_color white
    default_outline_color black
    default_shade_color black
    draw_borders no
    draw_graph_borders yes
    #draw_outline yes
    draw_shades yes
    use_xft yes
    xftfont DejaVu Sans Mono:size=10
    gap_x 5
    gap_y 5
    minimum_size 5 5
    net_avg_samples 2
    #no_buffers yes
    double_buffer yes
    out_to_console no
    out_to_stderr no
    own_window yes
    own_window_transparent yes
    own_window_class Conky
    own_window_type desktop
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_page
    stippled_borders 0
    update_interval 1.0
    uppercase no
    use_spacer none
    show_graph_scale no
    show_graph_range no
    TEXT
    $nodename - $sysname $kernel on $machine
    Uptime:$color $uptime
    $hr
    CPU > ${freq}MHz ${hr 1}$color
    CPU Usage:$color $cpu% ${cpubar 4}
    ${cpugraph 15,280 ffffff 00A2FF}
    MEMORY $memmax ${hr 1}
    RAM : $mem / $memperc%${alignr}${membar 6,120}
    I/O : ${diskio}${alignr}${diskiograph 6,120}
    DISK > /dev/ ${hr 1}$color
    Root ( sda3 ): ${fs_free /} ${fs_bar 6 /}
    Home ( sda4 ): ${fs_free /home} ${fs_bar 6 /home}
    Movies ( sdb1 ): ${fs_free /home/movies} ${fs_bar 6 /home/movies}
    Windows ( sdc1 ): ${fs_free /mnt/sdc1} ${fs_bar 6 /mnt/sdc1}
    NETWORK > ${addr eth0} ${hr 1}$color
    ${downspeedgraph eth0 15,135 ffffff 00A2FF} ${upspeedgraph eth0 15,135 ffffff 00A2FF}
    Down / Up Speed: ${downspeed eth0} k/s / ${upspeed eth0} k/s
    Down / Up Bytes: ${totaldown eth0} / ${totalup eth0}
    Inbound / Outbound / Total: ${tcp_portmon 1 32767 count} / ${tcp_portmon 32768 61000 count} / ${tcp_portmon 1 65535 count}
    PROCESSES > ${processes} / ${running_processes} ${hr 1}$color
    NAME PID CPU% MEM%
    ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
    ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
    ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
    ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
    ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}
    ${exec feh --bg-scale "`grep 'wallpaper=' ~/.kde4/share/config/plasma-appletsrc | tail --lines=1 | sed 's/wallpaper=//'`"}
    here's my xorg.conf as well if it helps. if there is anything someone can suggest adding or removing from it, especially to tweak video performance, i'm wide open for suggestions while im here
    Section "ServerLayout"
    Identifier "Xorg Configured"
    Screen 0 "Screen0" LeftOf "Screen1"
    Screen 1 "Screen1" 1600 0
    InputDevice "Keyboard0" "CoreKeyboard"
    InputDevice "PS/2 Mouse" "CorePointer"
    EndSection
    Section "Files"
    ModulePath "/usr/lib/xorg/modules"
    FontPath "/usr/share/fonts/misc:unscaled"
    FontPath "/usr/share/fonts/misc"
    FontPath "/usr/share/fonts/75dpi:unscaled"
    FontPath "/usr/share/fonts/75dpi"
    FontPath "/usr/share/fonts/100dpi:unscaled"
    FontPath "/usr/share/fonts/100dpi"
    FontPath "/usr/share/fonts/PEX"
    FontPath "/usr/share/fonts/cyrillic"
    FontPath "/usr/share/fonts/Type1"
    FontPath "/usr/share/fonts/ttf/western"
    FontPath "/usr/share/fonts/ttf/decoratives"
    FontPath "/usr/share/fonts/truetype"
    FontPath "/usr/share/fonts/truetype/openoffice"
    FontPath "/usr/share/fonts/truetype/ttf-bitstream-vera"
    FontPath "/usr/share/fonts/latex-ttf-fonts"
    FontPath "/usr/share/fonts/defoma/CID"
    FontPath "/usr/share/fonts/defoma/TrueType"
    EndSection
    Section "Module"
    Load "ddc" # ddc probing of monitor
    Load "dbe"
    Load "extmod"
    Load "glx"
    Load "bitmap" # bitmap-fonts
    EndSection
    Section "ServerFlags"
    Option "AllowMouseOpenFail" "true"
    Option "Xinerama" "1"
    EndSection
    Section "InputDevice"
    Identifier "Keyboard0"
    Driver "keyboard"
    Option "CoreKeyboard"
    Option "XkbRules" "xorg"
    Option "XkbModel" "pc105"
    Option "XkbLayout" "us"
    Option "XkbVariant" ""
    EndSection
    Section "InputDevice"
    Identifier "Serial Mouse"
    Driver "mouse"
    Option "Protocol" "Microsoft"
    Option "Device" "/dev/ttyS0"
    Option "Emulate3Buttons" "true"
    Option "Emulate3Timeout" "70"
    Option "SendCoreEvents" "true"
    EndSection
    Section "InputDevice"
    Identifier "PS/2 Mouse"
    Driver "mouse"
    Option "Protocol" "auto"
    Option "ZAxisMapping" "4 5"
    Option "Device" "/dev/psaux"
    Option "Emulate3Buttons" "true"
    Option "Emulate3Timeout" "70"
    Option "SendCoreEvents" "true"
    EndSection
    Section "InputDevice"
    Identifier "USB Mouse"
    Driver "mouse"
    Option "Device" "/dev/input/mice"
    Option "SendCoreEvents" "true"
    Option "Protocol" "IMPS/2"
    Option "ZAxisMapping" "4 5"
    Option "Buttons" "5"
    EndSection
    Section "Monitor"
    Identifier "Monitor0"
    VendorName "Unknown"
    ModelName "CRT-0"
    HorizSync 30.0 - 121.0
    VertRefresh 48.0 - 160.0
    ModeLine "1600x1200" 175.5 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync
    Option "DPMS" "true"
    EndSection
    Section "Monitor"
    Identifier "Monitor1"
    VendorName "Unknown"
    ModelName "SUN GDM-5410"
    HorizSync 30.0 - 121.0
    VertRefresh 48.0 - 160.0
    EndSection
    Section "Device"
    Identifier "Device0"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    BoardName "GeForce 7900 GS"
    BusID "PCI:2:0:0"
    Screen 0
    EndSection
    Section "Device"
    Identifier "Device1"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    BoardName "GeForce 7900 GS"
    BusID "PCI:2:0:0"
    Screen 1
    EndSection
    Section "Screen"
    Identifier "Screen0"
    Device "Device0"
    Monitor "Monitor0"
    DefaultDepth 24
    Option "TwinView" "0"
    Option "TwinViewXineramaInfoOrder" "CRT-0"
    Option "metamodes" "CRT-0: 1600x1200_75 +0+0"
    SubSection "Display"
    Depth 24
    EndSubSection
    EndSection
    Section "Screen"
    Identifier "Screen1"
    Device "Device1"
    Monitor "Monitor1"
    DefaultDepth 24
    Option "TwinViewXineramaInfoOrder" "CRT-0"
    Option "TwinView" "0"
    Option "metamodes" "CRT-1: 1600x1200 +0+0"
    SubSection "Display"
    Depth 24
    EndSubSection
    EndSection

    Hi @Arboria9 ,
    I see that you are experiencing issues printing two-sided from Yosemite. I would like to help you resolve this issue.
    You have pretty much have done all the steps that I would have provided.
    Are you still able to print two-sided from the Windows computer?
    Are you missing the option to select two-sided printing in the print driver?
    Check the driver name that is installed for the printer. Make sure it shows just the printer's name.
    Click the Apple menu and then click System Preferences. Click Printers & Scanners, highlight the printer name on the left side and on the right side of the screen it should show the printer's name. (Officejet 6500)
    If the full printer name isn't listed correctly, delete it and add the printer name back in from the list. Click the - sign to delete the driver and then click the + sign to add the driver, might have to click the drop down to select the printer's name to add it in.
    How was the printer name listed?
    If you need further assistance, just let me know.
    Have a great day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Given filename or path contains Unicode or double-byte characters.Retry using ASCII characters for filename and path What does this mean? it happen when I publish an OAM

    Given file name or path contains Unicode or double-byte characters. Retry using ASCII characters for filename and path
    What does this mean? It is happening when I try to publish an OAM for Dreamweaver.
    Also: How can I specify the browser in Edge Animate? It is just going wherever. Are there no Preferences for Edge Animate?
    BTW. Just call it Edge. Seriously. Do you call it Illustrator Draw? Photoshop Retouching?

    No, my file name is mainContent.oam
    My project name is mainContent.an
    This error happens when I try to import into Dreamweaver. Sorry, I wasn't clear on that earlier.
    I thought maybe it was because I had saved my image as a png. So re-saved as a svg, still get the error.
    DO I have a setting is Dreamweaver CC that is wrong? Should I try this in Dreamweaver CS6? I might try that next.
    Why is this program so difficult? I know Flash. I know After Effects. I can work the timeline part just great. It's always in the export that I have problems.
    On a MacPro, 10.7.
    Are you an Adobe person or just a nice helper?

  • Please Help!  I have been writing using - Pages - app for years.  I still can not figure out how to make single spaces between paragraphs.  Pages automatically double spaces between paragraphs.

    I have been writing on - Pages- app for several years.  Pages automatically uses double space between paragraphs. I can not figure out how to make single space between paragraphs. Tried everything.  Please help!  

    Pages User Guide >  http://manuals.info.apple.com/en_US/Pages_UserGuide.pdf
    Open the user guide then press Command + F on your keyboard.
    Type line spacing in the search field top right corner of that window.

  • Using ints or floats for Color

    Thanks in advance for taking time to read this message.
    I am using "Color" and need the most accurate color rendering. I found that I was losing some accuracy with Color(int, int, int), with integers ranging from 0-255. Because of this loss of accuracy, I am contemplating using Color(float, float, float) to make my colors. The float values can range from 0 - 1.
    "Theoretically" using integers one can effectively create 256^3 colors. How many colors can be created when using floats? More importantly, how do the float produced colors correspond to the more widely used int colors?
    Thanks,
    Every_man

    Assuming you want a RGB color scheme, you could get approx (2^22)^3 different colors, since a float has 2^22 bits for the mantissa (assuming you want an even spread between 0 and 1).
    When using Color(float, float, float) Java will try to map these values to the available system as best as possible. Therefore if your system can hadle more than 256 values for each of the RGB values you should get better color resolution.
    If you system does not use RGB encoding, you should probably use Color(ColorSpace, float[], float)

  • Double Float Margin Bug "error"

    I did a browser compatibility check on one of the pages that
    I am building and got this error.............
    "Line 112, Double Float Margin Bug 'error'
    When a margin is applied to a floated box on the same side as
    the direction of the float, the margin is doubled. This bug only
    affects the first float in a row of one or more floats.
    Affects: Internet Explorer 6.0
    Likelihood: Very Likely"
    I have many thumbnails for a gallery page in their own divs,
    within the content div, and they are floated in there.
    When I viewed solutions, they suggested:
    "When a margin is applied to a floated box on the same side
    as the direction the box is floated AND the floated box is the
    first one inside its containing box, the margin is doubled. (In
    other words, a left-floated box with margin-left set to move it
    away from its containing box will be twice as far away from the
    left edge of the containing box as intended.)
    SOLUTION
    Specify display: inline; for the affected float.
    DETAILED DESCRIPTION
    This bug only reproduces when the floated element's margin
    extends in the same direction as the float itself, and is between
    the float and the container box's inside edge. Subsequent floats
    with similar margins won't reproduce this bug- just the first float
    in any row of floated elements."
    Does anyone have any solutions, suggestions as how to fix
    this? I will attach my code. And if anyone has a better solution as
    to laying my thumbnail divs in another div container, please say
    so. The reason I am putting them in separate divs is because that
    is what someone suggested to use them with Lightbox2. He said they
    needed some kind of special CSS to enable some of the functions and
    they (the thumbnails) were easier to style if they were in their
    own separate divs. I'm open for any suggestions.
    Thanks!

    Just add "display:inline" to the styling like this:
    .image {
    background-color: #121922;
    height: 100px;
    width: 100px;
    float: left;
    margin: 20px;
    display: inline;
    }

  • How to convert value from exp. value to double/float???

    Hi all,
    I am fetching values from database, which is of type double / float.
    eg. values will be like -22,777,548 will be stored in database.
    NOw if i use
    float a= rs.getFloat(1);
    out.println("a="+a);
    I get output as a= -2.2777548E7
    I want to remove "E" from out put value and display as it was given in DB.
    How to solve this problem?
    Please Help!
    Regards
    Ashvini

    What do you mean - 'how does it work' ? All format classes (MessageFormat, DecimalFormat , SimpleDateFormat etc) are used to convert data from one form to other. Go through the java.text.* api. They work based on some pattern searches, pattern matches etc - dont know in detail :)
    As for the other things, thanks :)
    cheers,
    ram.

  • How to use Double selection If statements?

    Ok, this is what I have to do:
    Present a menu to the user from which there will be 6 choices, A = add three number, S = subtract 2 numbers, M = multiply three numbers, D = divide two numbers, O = modulus two numbers, E = Exit.
    2) If the user enters an A,S,M,O,D the program will prompt the user for numbers and perform the needed math on them.
    3) if the user enters an E then the program will thank the user, and exit.
    4)the program HAS to use Double Selection If Statements (no idea how to do these)
    5) the program should use float point numbers for all the numbers entered, besides modulus.
    heres what i have so far.. -_-
    import javax.swing.JOptionPane;
    public class Ifprogram
    public static void main (String[] args)
      String Intro;
      String A;
      String S;
      String M;
      String D;
      String O;
      String Exit;
      Intro = JOptionPane.showInputDialog(null, "Enter A to add 3 numbers \n S to Subtract two numbers \n M to Multiply three numbers \n D to Divide two numbers \n O to Modulus two numbers \n and E to Exit.");
       A = JOptionPane.showInputDialog(null, "You selected to add 3 numbers. Enter the first digit to add.");
       S = JOptionPane.showInputDialog(null, "You selected to substract two numbers. Enter the first digit to subtract.");
    }IM SO LOST.
    If anyone could give me some tips on what to do, or where to get, that'd help A LOT! Thank you.

    I can see that working, but
    if(user entered 'A') {
                        A = JOptionPane.showInputDialog(null, "You selected to add 3 numbers. Enter the first digit to add.");
                    } else if(user entered 'S') {
                       S = JOptionPane.showInputDialog(null, "You selected to substract two numbers. Enter the first digit to subtract.");
                   }Is not working..
    The errors i get:
    16 ')' expected
                   if(user entered 'A') {
                                    ^
    21: illegal start of expression
                    ^
    2 errors
    Tool completed with exit code 1Edited by: JackJ11 on Mar 16, 2010 4:29 PM

  • SQL*loader support database columns Of Binary Double/Float

    Does SQL*loader support database columns Of Binary Double/Float when applying Direct Path?

    Why not use Google and find out for yourself.
    The first hit on Google is this
    Go see for yourself
    Regards
    FJ

  • Correct way to use double type to represent money quantities

    I was assigned a project where I had to create a class that received money quantities as double numbers and that implemented a method returning a quantity of money as double. I have to use this scheme as we have no seen other data types in class.
    My question is, what can I do to make sure that the value I'm returning is a double number that looks like money. For example, I don't want my method to return 10.78889332., I want it to return 10.79. How can I do that? Is there any intended method for that?
    Can I let this issue like that and then take care of it in the test class by formating the output of the method when using it. I think this approach is not correct.
    Thanks for your time.

    See http://docs.sun.com/source/806-3568/ncg_goldberg.html
    There is no correct way to use double type to represent money quantities. You shouldn't be receiving them, you shouldn't use them, and you shouldn't return them. Floating-point is for science, not money.
    Use BIgDecimal.

  • Double - Float casting or Why isn't there float sqrt?

    Is there any reason why not to include float sqrt? I'm pretty pissed since, it is just... well plain stupid. I hope it can be added, not to mention that casting takes away performance, not much, but I have to do a lot of casting since I'm doing 3d grahpics... Anyone know any solluions? Is there any point going the hard way and implementing own sqrt for float?
    WHY WHY WHY, OH WHY.
    Something is rotten in the state of java.

    The absence of Math.sqrt(float) and float versions of other relevant methods is apparently becuase early versions of the Java compiler could not distinguish overloaded methods which only differed in double/float parameters. The current compilers do not have this problem and it has been proposed that the extra methods should be added but I don't know when this might happen.
    In any case how sure are you that casting between double and float is causing any significant performance problem? This cast is NOT particularly expensive (casting to 'int' from float or double is usually much more expensive).
    What processor are you using --- as far as I know Intel processors do not give any speed benefit from doing sqrt on float instead of double. I believe that many RISC processors do benefit from using float where possible.

  • Double/float/BigDecimal

    Hi all
    What is the major difference between
    double, float, BigDecimal inorder to use for
    the accurate results in currency calculations.
    Thanks in advance.

    double and float are basically the same, other than double is twice as large. They are not accurate. I belive that (you can test this yourself) if you:
    <code>
    double d = .001 + .001 + .001 + .001;
    System.out.println(d == 0);
    </code>
    you get true. at least something similar to above shows this.
    BigDecimal is incredibly large and it is accurate.

  • By default, on a mac keyboard F3 lets you see all the open apps and the such. However, I changed it so that I use those keys for keyboard shortcuts; But i'd like the normal F3 key to still work without me having to press FN.

    By default, on a mac keyboard F3 lets you see all the open apps and the such. However, I changed it so that I use those keys for keyboard shortcuts; But i'd like the normal F3 key to still work without me having to press FN.

    rajlego,
    in the Keyboard pane of System Preferences, select the Shortcuts tab, and then select Mission Control on the left-hand side. On the right-hand side, make sure that the Mission Control checkbox is checked, double-click on its current key combination (by default “^↑”) so that the key combination is highlighted, and then press the F3 button — that will set its shortcut to be F3. You can now press F3 to bring up Mission Control without needing to also press the Fn button.

  • I've been using Aperture now for the past 7 months and really happy with it, however in the past two days any photos I download are heavily pixelated and blurry. When I download the same shots to any other program they are fine.

    Hi,
    I've been using Aperture now for several months without any issues except for the last couple of days...when I now download my shots from the memory card the photos are heavily pixelated and blurry but when loaded to iPhoto they are fine.
    Can someone tell me what the problem could be and how to fix it.

    Is Aperture doing any processing?  ("Window→Show Activity" -- anything there?)
    Are the Images pixilated/degraded when shown in the Viewer as well as in the Browser?  (Double-click an Image to open it in the Viewer.)
    How 'bout at 100%? (In the Viewer, press "z" to zoom to 100%.  The "z" key toggles the zoom.)
    Does generating a new Preview remove the pixilation?  (Select an Image in the Browser, hold down "{Option}" and click "Photos→Generate Preview".)

Maybe you are looking for