i dont think the program would be useful if you can't use the same image as me, but how do you set the alpha property? Does it have something to do with the AffineTransform class?
Printable View
i dont think the program would be useful if you can't use the same image as me, but how do you set the alpha property? Does it have something to do with the AffineTransform class?
Without a program that shows the problem, I can't work on a solution.
Build one in the program or attach it to the forum's thread.Quote:
use the same image as me
how do you set the apha thing you mentioned
Look at the Color class.
there are no set methods in the color class... so how do you modify the alpha value?
See the PixelGrabber class for ways to change colors.
this class seems to be able to retrieve color and modify it on an image, but how can I use it to make parts of the image opaque?
The color's alpha value controls opaqueness.
this snippet of code is supposed to make a single color transparent, but I dont understand anything but bits and pieces of it. Can you help me to do so? First off, is there a good tutorial somewhere for RGB image filters, b/c I havn't ever used them before. Next the return statement, I don't understand the logic of it or the purpose of the shift operator.
Code:private Image TransformGrayToTransparency(BufferedImage image)
{
ImageFilter filter = new RGBImageFilter()
{
public final int filterRGB(int x, int y, int rgb)
{
return (rgb << 8) & 0xFF000000;
}
};
ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(ip);
}
Where there any comments by the author of the program explaining what it does? I've never used a filter.
To see what the shift operator does, print out the int value before and after the shift to see what if does.
Use the Integer class's toHexString() method to format the int value to see what happens to the bits in the int variable.
I really just want an explination of that return statement at the moment.
here is where I got that code:
java - How to make a color transparent in a BufferedImage and save as PNG - Stack Overflow
Quote:
explination of that return statement at the moment.
Read th API doc for the class and method it uses.Code:return Toolkit.getDefaultToolkit().createImage(ip);
not that return statement, the one on line 7. I don't understand why he has hexadecimal numbers there, or why the book that taught me what hexadecimal was said it was used often when working with color values...
As I said before add a println statement to print out the values that are created by the shift and & to see what they do. Write a 5 line program that does some shifts and ANDs and print out the before and after to see what happens.
Hexadecimal numbers are easier to understand when used with the AND(&) and OR(|) operators. You can see that the AND is clearing all the bits except for the top (leftmost) 8 bits. You use AND to clear bits and OR to set bits.
I am going to play around with hexadecimal numbers for a bit... In the meantime, I have wracked my brain, but cannot think of any way to do what I need. this program below draws a line from the point (250,250) to wherever you click, a black dot also flies across the screen. Pretend that the player is at the point (250,250). I want to make it so that wherever I click It will fire a black ball in that direction, but I cannot think of a way to do this that will work for every direction. Any thoughts?
Fram:Code://this can be used to rid yourself of flickering
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Rectangle;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.geom.Ellipse2D.Double;
import java.awt.geom.Ellipse2D;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class TRYBufferStrategy extends Fram implements MouseListener
{
Panel base = new Panel();
Canvas canvas = new Canvas();
Timer t = new Timer();
int x=50,y=50, count=0,mx=250,my=250;
BufferStrategy strategy;
BufferedImage face;
Ellipse2D shot = new Ellipse2D.Double(50,50,5,5);
TRYBufferStrategy()
{
super("TRYBufferStrategy");
setSize(800,600);
//setIgnoreRepaint(true);
add(base);
//canvas.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
setIgnoreRepaint(true);
base.setLayout(null);
base.add(canvas);
canvas.setBounds(0,0,getWidth(),getHeight());
canvas.setIgnoreRepaint(true);
canvas.addMouseListener(this);
//setUndecorated(true);
setVisible(true);
try
{
face = ImageIO.read(getClass().getClassLoader().getResource("pic/hills.jpg"));
}
catch(IOException e) {}
canvas.createBufferStrategy(2);
strategy = canvas.getBufferStrategy();
t.schedule(new TimerTask()
{
public void run()
{
++count;
strategy = canvas.getBufferStrategy();
do
{
do
{
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
render(g);
g.dispose();
}while(strategy.contentsRestored());
strategy.show();
}while(strategy.contentsLost());
if(count==100)
{
count=0;
cancel();
}
}
},2000,10);
}
public void render(Graphics2D g2)
{
x+=5;
shot.setFrame(x,(x/5),5,5);
g2.drawImage(face,0,0,null);
g2.fill(shot);
g2.drawLine(250,250,mx,my);
}
public void mouseClicked(MouseEvent event)
{
mx= event.getX();
my= event.getY();
t.schedule(new TimerTask()
{
public void run()
{
++count;
strategy = canvas.getBufferStrategy();
do
{
do
{
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
render(g);
g.dispose();
}while(strategy.contentsRestored());
strategy.show();
}while(strategy.contentsLost());
if(count==1)
{
count=0;
cancel();
}
}
},0,10);
}
public void mouseEntered(MouseEvent event)
{
//System.out.println("enter");
}
public void mouseExited(MouseEvent event)
{
//System.out.println("exit");
}
public void mousePressed(MouseEvent event)
{
//System.out.println("pressed");
}
public void mouseReleased(MouseEvent event)
{
//System.out.println("released");
}
public static void main(String[] args)
{
TRYBufferStrategy a = new TRYBufferStrategy();
}
}
Code:import java.awt.event.*;
import java.awt.*;
public class Fram extends Frame implements WindowListener
{
public Fram(String str)
{
super(str);
addWindowListener(this);
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowClosed(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
Get rid of Fram, extend JFrame and add this one line:Code:setDefaultCloseOperation(EXIT_ON_CLOSE);
ikr... but thats unimportant at the moment, do you have any ideas about the previous post?
It's important to me because I change every post to get rid of Fram.