Show Posts
|
|
Pages: [1] 2
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: Save Image data
|
on: 2004-11-02 14:00:50
|
|
Thanks for the response. I’m not looking for saving image data as any kind of image format as described in imageIO. I just need to save a buffered image data using simple IO and restore back if needed. By doing this way, I can get much better IO performance when I create multiple levels of undo image on disk.
Basically, I can undo an image changes by using the following sequence :
//copy image original data into int[] data
BufferedImage.getRGB(0, 0, w,h, data, 0, w);
//Make some changes to bufferedImage
//undo the changes by restoring back data BufferedImage.setRGB(0, 0, w,h, data, 0, w);
This works fine except that I have to use a lot of memory to store multiple undo data for creating multiple undo. In order to avoid that, I want to save data array not the entire image on disk. I tried with BufferedInputStream to read back the saved data as int type but it appears that the data was changed when it was saved using BufferedOutputStream.
Does anyone know a better way to create multiple undo for a large image without consuming too much memory while maintaining relatively good performance ?
Jay
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Save Image data
|
on: 2004-11-01 18:48:59
|
|
I want to save an image data into a file via FileOutputStream and restore back as needed through FileInputStream, such as :
Save :
int[] data; BufferedImage.getRGB(0, 0, w,h, data, 0, w);
Save data via FileOutputStream
Restore:
Get data back via FileInputStream BufferedImage.setRGB(0, 0, w,h, data, 0, w);
The problem is both FileInputStream and FileOutputStream require byte[] not int[]. How can I convert int[] to bye[] and visa efficiently or Java has something allow you to save buffered image data into a file and restore back as needed ?
Jay
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / animated selection border
|
on: 2004-10-14 14:03:36
|
|
Does anyone know how to create an animated selection highlight ? I do not know what it is called it but it’s very common in window applications. The one with short black and white lines chase each other along the border of a selection. One example can be seen when a cell in Microsoft Excel is marked for copy.
Jay
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / Release of Tiger
|
on: 2004-09-30 13:56:50
|
|
Just downloaded a copy of Tiger. Not very impressive. Still require large footprint when loading images. But it appears to be that applications startup is much faster.
The ‘setTooltipText’ nolonger works under 1.5, which works fine under 1.4. In order to show the tool tip text under 1.5, the panel where the component reside has to get focused. I reported this prior to the release, but apparently they did not address this issue.
|
|
|
|
|
8
|
Java Game APIs & Engines / Java 2D / Re: standard indexed color table
|
on: 2004-08-14 18:47:23
|
|
The optimal palette. Where can I find more information about it ? I tried different color reducing algorithms such as octree along with dithering process. But I found that using bufferedimage is the pretty easy, efficient and produces good results.
|
|
|
|
|
9
|
Java Game APIs & Engines / Java 2D / standard indexed color table
|
on: 2004-08-13 19:26:13
|
|
The following color table can be used to convert a RGB image to an IndexColorModel image with 16 colors. Does anyone know how to create the color tables of 32, 64, 128 ,256 colors for IndexcolorModel image. ?
int[] cmap = { 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, //8 primary colors 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff, // ... 0xff1c1c1c, 0xff383838, 0xff555555, 0xff717171, //8 shades of gray 0xff8e8e8e, 0xffaaaaaa, 0xffc7c7c7, 0xffe3e3e3 };
Jay
|
|
|
|
|
10
|
Java Game APIs & Engines / Java 2D / Re: deal with large buffered image
|
on: 2004-05-13 17:08:35
|
|
The original image size varies with the largest one about 1.2M. This is what I tried to implement in my code :
Image origImage=new ImageIcon(imageName).getImage(); BufferedImaeg drawCanvas = gc.createCompatibleImage(imgW, imgH,Transparency.TRANSLUCENT);
draw_g2=drawCanvas.createGraphics();
BufferedImage backupCanvas = gc.createCompatibleImage(imgW, imgH,Transparency.TRANSLUCENT);
backup_g2=backupCanvas.createGraphics();
backup_g2.drawImage(drawCanvas, 0,0, this); // create undo
//perform drawing tasks .. draw_g2.fillRect(…); draw_g2.drawLine(…); …..
//undo the changes
draw_g2.drawImage(backupCanvas, 0,0,this);
This works fine except it uses too much memory when the original image is large. I’m trying to figure out a way to reduce the memory usage by not to create a buffered image for storing the image backup. Creating an undo stack may be an option but I do not know if the undo stack would work if the changes are the actual pixels changes of the original image.
Yes you are correct. I do not have issue if I increase the heap space but I want to see if there better solution in the code itself.
|
|
|
|
|
11
|
Java Game APIs & Engines / Java 2D / deal with large buffered image
|
on: 2004-05-13 15:58:44
|
|
What is the effect way to create an image undo? I have a large buffered image, which I need to manipulate but also want to be able to undo the changes. I create another buffered image to save the original image prior to the changes. But I constantly get out off memory error. Maybe I can save some memory by creating the undo image as a non-buffered image.
What is the difference between an image and buffered images in terms of sizes? How can I create a new non-buffered image from a buffered image?
I use to follow method to try to create a new image from a buffered image. But what I get is the same image object being converted from buffered to non-buffered :
image=bufferedImage.getSource();
I need to create a new non-buffered image from a buffered image.
Jay
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / Re: copy a part of component image
|
on: 2004-05-10 18:35:58
|
|
Thanks for the response. But how do you pass an affinetransform to paint ? I must have done something wrong :
public static BufferedImage partOfImage(JComponent comp, int x, int y, int w, int w) { BufferedImage bimage; AffineTransform atX=new AffineTransform(); bimage=gc.createCompatibleImage(w,h,Transparency.TRANSLUCENT); Graphics2D g=(Graphics2D) comp.getGraphics(); atX.translate(-x,-y); g.setTransform(atX); comp.paint(bimage.createGraphics()); return bimage; }
This does not give what I need. I probably need to pass atX to paint not via g.setTransform(atX).
Thanks
Jay
|
|
|
|
|
14
|
Java Game APIs & Engines / Java 2D / copy a part of component image
|
on: 2004-05-10 15:39:49
|
|
Is there any way to get part of a component image ? This is the way to copy entire component image to a buffered image :
Comp.paint(bi.createGraphics());
If I do this, I have to create a large buffered image and then cut off the part of image that I need. I wonder if it is possible to only copy the part of a component image to small buffered image ?
Jay
|
|
|
|
|
15
|
Java Game APIs & Engines / Java 2D / coordinate transformation
|
on: 2004-05-05 14:17:16
|
|
What is the correct method to calculate each pixel’s coordinate translation after an image is zoomed around center ? I’m using the following steps to zoom an image around it’s center :
AffineTransform atT=new AffineTransform();
int dx=img.getWidth()/2; int dy=img.getHeight()/2;
atT.preConcatenate(AffineTransform.getTranslateInstance(-dx, -dy));
atT.preConcatenate(AffineTransform.getScaleInstance(scale, scale));
atT.preConcatenate(AffineTransform.getTranslateInstance(dx, dy));
g.drawImage(img,atT, this);
How can find out each pixel’s coordinate translation after zooming ?
Thanks,
Jay
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / keep application on top
|
on: 2004-04-09 13:36:30
|
|
Does anyone know how to keep a Java application always on top in a window desktop environment? And also how to add the application icon to the window toolbars at bottom of the screen?
Thanks
Jay
|
|
|
|
|
17
|
Discussions / Miscellaneous Topics / Java License
|
on: 2003-12-22 14:44:58
|
|
Does anyone know where I can find a list of Java technologies, which are free for commercial usage? From Sun web site, it looks like that J2SE, J2EE and J2ME are free.
http://servlet.java.sun.com/help/legal_and_licensing/#498
I'm thinking about using JAI (Java Advanced Image) in my application, but do not know if JAI APIs are free. If they are not, how can I acquire the license from Sun ?
|
|
|
|
|
19
|
Java Game APIs & Engines / Java 2D / Re: get the polygon around a point
|
on: 2003-11-07 15:51:53
|
|
Thanks Tom for leading me to flood fill. I think that I understand basically how flood fill works.
But how can I detect a border color? For instance, if a polygon has 12 line segments and each line segment has a different color. In order to fill this polygon with a color using flood fill , I have to detect all 12 colors and keep track each pixel as the color filling moves toward the polygon border.
Jay
|
|
|
|
|
21
|
Java Game APIs & Engines / Java 2D / Re: get the polygon around a point
|
on: 2003-11-06 12:47:11
|
|
Tom, basically, I need to implement the same function as "fill with color tool" of MS paint. Draw any polygons on a canvas and then selectively fill them with colors after all the polygons are drawn on the canvas.
Try to find a better way to do it without keeping track of all the polygons drawn and their intersections.
Jay
|
|
|
|
|
27
|
Java Game APIs & Engines / Java 2D / Re: bright only non-transparent pixels
|
on: 2003-09-26 13:07:28
|
|
The problem was caused by the way that the color indexed images were converted to RGB images . If I use BufferedImage.TYPE_INT_ARGB instead of BufferedImage.TYPE_INT_RGB , the transparent pixels work fine with ConvolveOp operation. But with Rescale, I got nothing drawn on the screen if the buffered image was created using BufferedImage.TYPE_INT_ARGB .
public static BufferedImage rgbImage(Image image) { BufferedImage bimage=new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_ARGB);
Graphics2D g=bimage.createGraphics(); g.drawImage(image,0,0,null); g.dispose(); return bimage; }
public static BufferedImage brightImage(BufferedImage bI, float scaleFactor) { BufferedImage bi;
BufferedImageOp op=new RescaleOp(scaleFactor,0,null); bi=op.filter(bI,null); return(bi); }
Jay
|
|
|
|
|
28
|
Java Game APIs & Engines / Java 2D / Re: bright only non-transparent pixels
|
on: 2003-09-19 14:34:38
|
|
Thanks for the response. The reason that I only want to bright the non-transparent pixels is that all the transparent color shows up as black when I apply the RescaleOp to a gif image which has transparent background . It appears that RescaleOp alters alpha channels as well.
When I followed your suggestion by creating a new RescalOp as
new RescaleOp(new float[]{scaleFactor,scaleFactor,scaleFactor,0},new float[]{1,1,1,0},null);
I received the following error:
java.lang.IllegalArgumentException: Number of scaling constants does not equal the number of color or color/alpha components at java.awt.image.RescaleOp.filter(RescaleOp.java:323)
|
|
|
|
|
29
|
Java Game APIs & Engines / Java 2D / bright only non-transparent pixels
|
on: 2003-09-18 18:28:05
|
|
Does anyone know how to make only the non-transparent part of an image bright or dark ? I tried the following code but it appears that rescalOp applies to every pixel of an image , non-transparent as well as transparent:
public static BufferedImage brightImage(BufferedImage bufferedImage) { BufferedImage bi;
float scaleFactor = 1.2f; RescaleOp op = new RescaleOp(scaleFactor, 1, null); bi = op.filter(bufferedImage, null); return(bi); }
Jay
|
|
|
|
|
30
|
Java Game APIs & Engines / Java 2D / Re: stack buttons
|
on: 2003-07-28 17:19:41
|
Thanks guys. Yes, it works by creating a JPanel with null option and then placing the buttons wihtin the jpanel. But I have one little issue. I could not make one button always remaining behind the other one, even I set the button behind to none focusable. When I cliked the button behind, it shows up in front : import java.awt.*; import java.awt.event.*; import javax.swing.JPanel; import javax.swing.JButton; public class ButtonStack { public static void main (String args[]) { final JButton jb1,jb2; Frame frame = new Frame("Example of Overlap Buttons"); frame.setBounds (100, 100, 300, 300); jb1=new JButton(); jb1.setBackground(Color.red); jb1.setFocusable(false); jb2=new JButton(); jb2.setBackground(Color.blue); JPanel jPanel=new JPanel(null); jb1.setBounds(120,120,100,100); jb2.setBounds(140,140,100,100); jPanel.add(jb2); jPanel.add(jb1); frame.add(jPanel,BorderLayout.CENTER); frame.addWindowListener (new WindowAdapter() { public void windowClosing (WindowEvent e) { System.exit (0); } } ); frame.show(); } } By the way, there is an exmaple about using TableLayout to create overlap buttons: http://java.sun.com/products/jfc/tsc/articles/tablelayout/Simple.html
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|