This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I can write my JPanel to an image, and read that image and dislpay it to the JPanel, but can't draw more or "add" to that image when it's loaded. Do I need to use a bufferedimage or will a plain "image" be ok? I assume this is GUI related as the images load and save ok. Here's what happens ideally:
1. List of items chosen.
2. Picture drawn in DrawingPanel (extends JPanel) and saved by list index
3. When the list is loaded again, the picture comes up. User can draw on it and save it again if neccessary.
4. Picture saved again.
The trouble happens when the picture is loaded up a second time. I can either write pictures the the hdd, or read them and display them... Can't do the last step
How image is stored:
The paintComponent method in PaintPanel: (where the picture is drawn - PaintPanel is a nested class, in a JFrame.)
I have a feeling the paint method isn't set up to write over an existing picture? I know the jpg quality is going to deteriorate as well; I just want to be able to re-write over a jpg when it's loaded up and save the altered image.
Thanks a lot Craig, I notice you're using a png file as well. I'd noticed some compression artefacts in my jpg when saved, as I'd gone with the default encoding settings and not played around with it on that front, but I think I'll play around with the formats and see what I can do.
Joined: Jan 30, 2009
HAHA! Victory is mine! I've used some of your code Craig, but the important thing is I understand what was going on and why it didn't work. I *was* loading up the image but not creating a graphics context from it, so I used to be able to load an image and se eit, or draw one and not edit it... Fixed now - the heart of it was:
Notably, I also didn't see this as I was at first drawing with a white colour on a white background. Sometimes even the simple things can catch you out eh?... On an asides, drawing and painting in Java is a real pain isn't it? Or is it just me? I mean I whacked a program together like this in C# on visual studio in half an hour... Oh well. I'm hardly a coding guru anyway. Thanks again for your help Craig