Changing brightness and colors of an image

Here's code for an applet that will create a gradient:
http://www.sitepoint.com/forums/showpost.php?p=1408696&postcount=5
How would you load an image and do this same thing to the image?
Also, how could you add a slider to change the brightness?
Any tips or code samples would be much appreciated.

Here's the code that changes the rgb values. But, it doesn't work in some browsers and earlier versions of jre. Can you fix it so that it works? Also, how would you add to this code to make it change the brightness of an image?
(2 files: grad.java and myPaint.java)
File: grad.java
import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import java.awt.Rectangle; import javax.swing.JApplet; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class grad extends JApplet implements ChangeListener { JSlider[] jss; JPanel mainP, slidP; display disp; Color col1, col2; public void init() { mainP = new JPanel(new GridLayout(1, 2)); slidP = new JPanel(new GridLayout(6, 2)); jss = new JSlider[6]; for (int loop = 0; loop < 6; loop++) { jss[loop] = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 0); jss[loop].addChangeListener(this); } slidP.add(new JLabel("Red 1"), slidP.add(jss[0])); slidP.add(new JLabel("Green 1"), slidP.add(jss[1])); slidP.add(new JLabel("Blue 1"), slidP.add(jss[2])); slidP.add(new JLabel("Red 2"), slidP.add(jss[3])); slidP.add(new JLabel("Green 2"), slidP.add(jss[4])); slidP.add(new JLabel("Blue 2"), slidP.add(jss[5])); //add others in order r1, g1, b1, r2, g2, b2; disp = new display(); mainP.add(disp); mainP.add(slidP); getContentPane().add(mainP); } public void stateChanged(ChangeEvent evt) { col1 = new Color(jss[0].getValue(), jss[1].getValue(), jss[2].getValue()); col2 = new Color(jss[3].getValue(), jss[4].getValue(), jss[5].getValue()); disp.setColors(col1, col2); System.out.println("grad.stateChanged()"); disp.repaint(); } class display extends JComponent { Color col1, col2; public display() { col1 = Color.black; col2 = Color.black; } public void setColors(Color col1, Color col2) { this.col1 = col1; this.col2 = col2; } public void paint(Graphics _g) { Graphics2D g = (Graphics2D) _g; int boxW = 300; int boxY = 300; g.setPaint(new GradientPaint(0, 0, col1, boxW, boxY, col2)); g.fill(new Rectangle(0, 0, boxW, boxY)); } } }
File: myPaint.java
import java.awt.Color; import java.awt.Paint; import java.awt.PaintContext; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.ColorModel; import java.awt.image.Raster; import java.awt.image.WritableRaster; /* * Created on 16.09.2004 */ public class myPaint extends Object implements Paint { private Color c1, c2; public myPaint(Color c1, Color c2) { this.c1 = c1; this.c2 = c2; } public int getTransparency() { return OPAQUE;//this constant is in Paint class; } public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) { return new myPaintContext(c1, c2); } class myPaintContext implements PaintContext { private int r1, g1, b1, r2, g2, b2; myPaintContext(Color c1, Color c2) { r1 = (c1.getRGB() >> 16) & 0xff; g1 = (c1.getRGB() >> 8) & 0xff; r1 = c1.getRGB() & 0xff; r2 = (c2.getRGB() >> 16) & 0xff; g2 = (c2.getRGB() >> 8) & 0xff; b2 = c2.getRGB() & 0xff; } public ColorModel getColorModel() { return ColorModel.getRGBdefault(); } public Raster getRaster(int x, int y, int w, int h) { WritableRaster raster = getColorModel().createCompatibleWritableRaster(w, h); int[] data = new int[w * h * 4]; int base = 0; float rat1, rat2; for (int xloop = 0; xloop < w; xloop++) { rat1 = ((float) xloop) / ((float) w);//this is ratio of color1 rat2 = 1 - rat1;//this is ratio of color2; for (int yloop = 0; yloop < h; yloop++) { data[base++] = (int) ((r1 * rat1) + (r2 * rat2)); data[base++] = (int) ((g1 * rat1) + (g2 * rat2)); data[base++] = (int) ((b1 * rat1) + (b2 * rat2)); data[base++] = 255;//alpha } } raster.setPixels(0, 0, w, h, data); return raster; } public void dispose() {} } }

Similar Messages

  • Evening Out The Brightness and Color of a Set of Images

    So I have a set of images, usually between 500-700, all taken in a 20min period or so. Natural light through a window. It's shot handheld with my Canon rebel with a 18-55mm lens. Due to the slight change in light over the time period, the fact I'm zooming in and out, and moving around the subject, I get a lot of value and color variation. See the images below...
    My current process is to manually color correct each image so they match in terms of brightness and color. This gets very tedious of course. Could someone suggest a faster, preferably completely automated way to even out the brightness and colors of a set of images like these in lightroom so they all look pretty similar to each other?
    Thanks for any help!
    - Neil

    Hi léonie,
    >> One problem - it is not only the different color of the light because of the setting sun.
    >> Your Harry and Harold are receiving the sun light from different directions. Harold is
    >> facing away from the sun and the light in the shadows is much bluer. I doubt you will
    >> be able to "Lift&Stamp" the adjustment between these two groups of images without
    >> fine tuning it. The "shady" Harold will need additional color correction to turn the bluish
    >> shadows into sunlight, because the shadow regions need contrast stretching and
    >> more vibrancy as well.
    Yup, that's one reason I think I need a color correction after the fact method to handle this situation, obviously taking a shot that's mostly in shadow will look different than one where the character is almost all in complete sunlight.
    I guess I'm really having three issues here, first is the blue tint that gets introduced when I zoom in, and then second is the natural lightening and darkening that occurs as I take photos of the subject from different angles, and third is the fact since its sunlight the light does change somewhat over the 20minute period.
    Hopefully the first issue can be solved by turning off automatic white balance, and I'm still hoping there may be some automated method for evening out the value difference introduced by the 2nd and third issue. Although even if I can just solve the first issue that would save me a ton of time.
    Thanks for the info so far.
    - Neil

  • Why I cannot change font  and Color in JFrame title??

    Dear sir:
    I try to change font and Color in JFrame title in code below,
    It display all html code, not expected formatted ones.
    but fail. Looks like no way to do it??
    Can somebody help??
    Thanks
    import java.awt.BorderLayout;
    import java.awt.Toolkit;
    import javax.swing.*;
    public class JFrameTester {
      public static void main(String[] args) {
         String iconPath ="file:C:/eclipse/workspace/Test/images/long.PNG";
         String title = "<html><body bgcolor=\"yellow\">" + "<img src=\""+iconPath+"\">" +
              " <font size=\"6\" face=\"Verdana\" color=\"red\"><b>"+ "New Tester" + "</b></font></html>";
        JFrame f = new JFrame(title);
        f.setIconImage(Toolkit.getDefaultToolkit().getImage("images/123.gif"));
        f.setSize(250, 250);
        f.setLocation(300,200);
        f.getContentPane().add(new BorderLayout().CENTER, new JTextArea(10, 40));
        f.setVisible(true);
    }

    Looks like no way to do it??depends on the L&F you want.
    here's one way
    import java.awt.*;
    import javax.swing.*;
    class JFrameTester {
      public static void main(String[] args) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.RED));
        UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.YELLOW));
        String title = "Hello World";
        JFrame f = new JFrame(title);
        f.getLayeredPane().getComponent(1).setFont(new Font("Tall Paul",Font.ITALIC,24));
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(250, 250);
        f.setLocation(300,200);
        f.getContentPane().add(new BorderLayout().CENTER, new JTextArea(10, 40));
        f.setVisible(true);
    }

  • How do I change font and colors back to default?

    I have changed the font and color of the text through the tools button and the options button and the content tab. I find nothing telling me how to change the font and colors back to default font and colors. Can you advise me? I'm using Windows 7 Home Premium OS. Thanks.

    Hi Brenda19605,
    You can use this article to set the fonts and colors: https://support.mozilla.org/en-US/kb/change-fonts-and-colors-websites-use?esab=a&s=font&r=0&as=s
    The default settings for the font are in this article:
    https://support.mozilla.org/en-US/kb/Some%20text%20shows%20up%20bold%20after%20upgrade
    Unfortunately for the default colors has no good reference. But for text it is black (most lower left) color, background is white (most upper left color). Unvisited links is blue (column 8, row 5) and visited link is purple (column 9, row 5).
    Let me know if you need anymore help!
    Lordfreak

  • Image changes brightness and contrast after importing. LR 5.3

    I'm importing RAW files straight from a CF card reader into my network storage drive via LR5.3. While reviewing as it imports initially each image looks great but a few seconds after it loads onto the screen it seems like LR applies a bit of extra brightness and lessens the contrast and I lose a load of detail that was there originally. I've not touched the import settings and no filters are being applied by myself on import.
    Thanks in advance.

    Andrew Rodney wrote:
    the initial prevew you see is wrong ... LR is showing you the correct preview ...
    I think I know what you're trying to say there Andrew, but to attempt a clarification for the OP (and other readers):
    * Lr's rendering may be considered "correct" in Lightroom because it's, well, Lightroom's rendering.
    Given the terminology posed by Andrew, in a Nikon software environment, Lightroom's rendering would be considered wrong, and Nikon's correct. And such is the perspective that many people bring to Lr - that Nikon's rendering should be considered "correct", and Lr's rendering should "match", and to the extent that it doesn't, it's "wrong"...
    The bottom line (from my perspective):
    Since Lr's rendering ignores camera settings (as manufacturer's rendering ignores Lightroom settings), one needs to learn to (set up defaults and) apply Lightroom settings to have the Lightroom rendering how they want..
    Cheers,
    Rob

  • Brightness and color loss

    I have a 13' macbook Aluminum 2008 .  My friend brought a newer Macbook pro and we compare the MacBooks and his lighting was brighter and the color was better. i check my battery cycle count and its over what the limit is. and every now and then my screen flashes off quicky black . Also my battery doesnt last 30 minutes.  Can the battery be the problem of my color and light loss

    Could be the battery, but have you changed Color LCD in System Prefrences?

  • 3rd party brightness and color options for quicktime?

    I have quicktime Pro. Unfortunately, my graphics card on my ibook 12 inch does not support the video options on A/V controls.
    I'd like to change the brightness and/or the colors of some of the movies I watch as sometimes they are rather dark or muted.
    On the pro version, I can't do this ( why? I don't know. Isn't it PRO?). I know there are other viewers like VLC that can but I don't want to have to use that because I like the clarity of quicktime.
    Are there any solutions to this problem? Maybe some third party add on that I can buy?
    Thanks very much.
    Howard VanWyden.
    imac g4 Mac OS X (10.3.8)
    imac g4 Mac OS X (10.3.8)

    Depends somewhat on the TV you have in mind.
    If a new HDTV you may have choice of HDMI (or DVI), component and composite inputs. Of course, some of those inputs may already be committed to cable, DVD, satellite, etc.
    If you have a wi-fi network you might even want to look into Apple TV; a friend was very enthused by his when we had breakfast together this morning.
    Phil

  • Hyperion web analysis can not change font and color

    In Hyperion web analysis, when I want to set or change font, a null dialogbox appear ; when I click and want to set or change color, nothing happen,even no dialogbox appears. Why?
    thanks advance!
    Edited by: user1016218 on 2010-1-8 上午7:16

    Hello,
    See my answer in this link:
    Urgently!  In Hyperion web analysis  font and color can not be changed
    May be it helps.

  • Using GREP styles for changing characters and colors

    Hello everybody,
    I have a question regarding GREP styles. I wish to change each letter of an alphabet in text to a square in a different color. For example: every 'a' in the text change to a yellow ■. I thought GREP styles would be perfect for it so I went to find/change, typed in my requests and InDesign told me it has found no 'a' in my text, which isn't possible. How do I fix it? And the other thing- is it possible to change the color of ■ ? Because i couldn't find the option.
    Please excuse me my incompetence, I am a new user of InDesign.
    Thanks in advance for your help! : )

    First off, it sounds like you want to use find/change with GREP, which is fine, rather than a GREP style, which is part of a paragraph style definition and cannot change the text in any way other than apply a character style to the found string, so would not help here.
    The not finding the text makes me think you've limited the search parameters in some way, either by limiting the scope to a selection, or by including a style or format requirement in the find options, perhaps.
    In order to do this, I think you are going to need to make use of the "other" category in the change dropdown and select Formatted Contents of Clipboard (which should clue you in that you need to make one of your colored squares and copy it to the clipboard before you run Find/Change). You can do this with either a plain text query or a GREP query, and there is no advantage to GREP in this case unless you want to match several different things and apply the same clipboard content to any of them.
    You'll need to run a separate find/change for each colored square. It might be possible to script a chain so it runs in a single operation, but that would also require swapping the colored sqaures on the clipboard which complicates things in this case. You might want to ask over in scripting: InDesign Scripting

  • SQL Server Management Studio has stopped working when changing fonts and colors

    I installed sql server management studio 2012 about 3 months ago to test drive and from time to time I'll attempt to change my background color of the TSql editor "In the fonts and colors option under tools"; however, the entire studio crashes
    and restarts.
    This has been ongoing since I first installed it 3 or 4 months ago, and have waited on posting to a fourm for help, assuming I am not the only one this is happening to I've waited for an update that might fix the issue.
    I've got to start on some heavy scripting and that god awful white background kills my eyes. I've got to have a black background or my work day is cut off by about 3 hours becuase of strain.
    What can I provide to someone that would help me with this?
    Thank you,
    Erik
    Specialize in software for the construction industry.

    Hello,
    Could you please apply the following updates and let us know the results?
    http://www.microsoft.com/en-us/download/details.aspx?id=35575
    http://support.microsoft.com/kb/2790947
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Changing Arrows and Color of a JScrollBar inside of a JScrollPane

    Hi. I can't believe this hasn't been asked and answered before but I can't find it in these forums if it has.
    I am trying to create a JScrollPane in a touchscreen based application - no mouse... The default scrollbar
    in my JScrollPane is too small for large fingers. I have successfully increased the size of the scrollbar
    to a usable size using: UIManager.put("scrollbar.width", 75).
    My next problem is two-fold.
    1) The arrows at top and bottom of the scrollbar are now heavily pixelated (i.e. jagged and blocky) and
    look like we zoomed in too much on a bitmap. How can I change these arrows to a graphic that is
    more related to the current size of my scrollbar?
    2) The color of the scrollbar is shades of 'baby blue'. My color scheme for my application is shades of
    beige or brown. This makes the scrollbar stand out like a sore thumb. How can I change the color
    of the scrollbar?
    Note: This is being coded in NetBeans 6.7.1 but I can't find any property in the visual editor that covers
    my problems.
    Also, I came across the UIManager.put("scrollbar.width", xx) from googling. Is there an official (complete)
    list of the properties available to the UIManager?
    Thanks

    To help out anyone who has been struggling with this as I have, here is the final solution we were able to use. We only needed to work with the vertical scroll bar, but it should be easy to work with now that a better part of the work is done. I do hope this is helpful.
         public ReportDisplayFrame()
              UIManager.put( "ScrollBar.width", 75);
              RDFScrollBarUI rdfScrlBarUI = new RDFScrollBarUI();
              rdfScrlBarUI.setButtonImageIcon( new ImageIcon( "C:/company/images/upArrow.jpg") , rdfScrlBarUI.NORTH);
              rdfScrlBarUI.setButtonImageIcon( new ImageIcon( "C:/company/images/downArrow.jpg") , rdfScrlBarUI.SOUTH);
              tempScrlBar = new JScrollBar();
              tempScrlBar.setBlockIncrement( 100);
              tempScrlBar.setUnitIncrement( 12);
              tempScrlBar.setUI( rdfScrlBarUI);
    // other constructor code //
              rdfScreenRedraw();
         private void rdfScreenRedraw()
              String methodName = "rdfScreenRedraw()";
              logger.log(Level.INFO, methodName + ": Revalidating: mainPanel Thread = ["+Thread.currentThread().getName()+"]");
              jPanelRpt.revalidate();
              jPanelRpt.repaint();
         class RDFScrollBarUI extends BasicScrollBarUI {
              private ImageIcon decImage = null;
              private ImageIcon incImage = null;
              public void setThumbColor(Color thumbColor) {
                   this.thumbColor = thumbColor;
              public void setThumbDarkShadowColor(Color thumbDarkShadowColor) {
                   this.thumbDarkShadowColor = thumbDarkShadowColor;
              public void setThumbHighlightColor(Color thumbHighlightColor) {
                   this.thumbHighlightColor = thumbHighlightColor;
              public void setThumbLightShadowColor(Color thumbLightShadowColor) {
                   this.thumbLightShadowColor = thumbLightShadowColor;
              public void setTrackColor(Color trackColor) {
                   this.trackColor = trackColor;
              public void setTrackHighlightColor(Color trackHighlightColor) {
                   this.trackHighlightColor = trackHighlightColor;
              public void setButtonImageIcon( ImageIcon theIcon, int orientation)
                   switch( orientation)
                        case NORTH:
                             decImage = theIcon;
                             break;
                        case SOUTH:
                             incImage = theIcon;
                             break;
                        case EAST:
              if (scrollbar.getComponentOrientation().isLeftToRight())
                                  decImage = theIcon;
                             else
                                  incImage = theIcon;
                             break;
                        case WEST:
              if (scrollbar.getComponentOrientation().isLeftToRight())
                                  incImage = theIcon;
                             else
                                  decImage = theIcon;
                             break;
              @Override
              protected JButton createDecreaseButton(int orientation) {
                   JButton button = null;
                   if ( decImage != null)
                        button = new JButton( decImage);
                   else
                        button = new BasicArrowButton(orientation);
                   button.setBackground( new Color( 180,180,130));
                   button.setForeground( new Color( 236,233,216));
                   return button;
              @Override
              protected JButton createIncreaseButton(int orientation) {
                   JButton button = null;
                   if ( incImage != null)
                        button = new JButton( incImage);
                   else
                        button = new BasicArrowButton(orientation);
                   button.setBackground( new Color( 180,180,130));
                   button.setForeground( new Color( 236,233,216));
                   return button;
         }

  • Changing Thumbnails and Color after re-opening LR

    Why does LR change each visible thumbnail along the bottom of the screen after, importing, then again after reopening of the program. Color Temp is set to "As Shot" but yet LR makes it a much cooler image thus changing the colors.
    Has anyone else experienced this??

    On a Mac, if you are not using a hardware calibrator, set the monitor profile to the default Color LCD, or do a "by-eye" calibration. Ian put up instructions for that here: http://computer-darkroom.com/colorsync-display/colorsync_1.htm . Contrary to windows machines, monitor profiles do not go bad on macs. You really really really should be calibrating using hardware however. Decent ones can be had for less than $100. To answer your original question. The color shift you are seeing initially is the subject of about 25% of the posts on this forum. What happens is that initially you see the embedded jpeg preview from your camera and after a short while, Lightroom replaces that with its own direct rendering from the RAW data. They simply represent different interpretations of what the camera sees. Usually the jpeg rendering done by the camera is more saturated and warmer than what Lightroom does in its default, rather boring rendering. Usually you have to work a little to get a great rendering out of Lightroom but you have amazing latitude. You don't have the latitude to do much with the jpeg from the camera anymore.

  • Screen losing brightness and color fading

    I have a 4 yr old Powerbook G-4 and the past two weeks have notices the brightness of the screen is fading as well as the images (screen saver). It is beginning to be difficult to see the files I have on my desk top. Will an adjustment help - what might that be? or do I have a much bigger problem?
    Thanks,
    Captain Krunch

    regarding bsteely's comment...
    don't use a screensaver???
    i have the middle macbook c2d...bought dec. 2006. i guess i have an lcd screen....so you're saying i shouldn't use a screensaver?? i have it set to run for 30 mins or 1 hr then sleep. it's of all my pictures...i really like it.
    i was taught to ALWAYS use a screensaver to prevent the screen from burning out.
    so what would you suggest as an alternative?
    what does anyone else think??
    --car

  • Ideacentre A520 All in One ~ brightness and color settings not saved

    the settings I choose with the touchbuttons on my A520 get lost when restarting. I would like to lower the brightness settings perminantly, how is this achieved?

    hi qwertydotNL,
    Can you try this instead
    1. Right click on an empty space on the desktop and launch Nvidia Control Panel
    2. On the left side, expand the Display sub menu and select Adjust Desktop color settings
    3. Adjust the brightness / contrast accordingly and reboot the machine
    If the problem persist, try to:
    4. Check if you have the Lenovo Dynamic Brightness System by searching it on the Metro UI, and reconfigure the settings or disable it to run on Startup.
    Spoiler (Highlight to read)
    Hope this helps
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • Changing size and color of mouse pointer...How? OSX  10.9.1

    I'm having problems seeing my mouse on the screen. It's really frustrating sitting down and not finding it, immediately.
    How do you change it? I just can't find it.

    Adjust cursor size in System Preferences > Accessibility > Display

Maybe you are looking for