• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Overwriting on a jpg in a Jpanel;

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Tau Slater
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks again
 
Tau Slater
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic