473,473 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drawing Images

6 New Member
I have a picture(a map) drawn to a panel using a BufferedImage and I want to draw circle on different parts of the map. I'm using a Graphics object to draw the circles onto the map but everytime I call the repaint function, everything I've drawn on the map disappears. Really need help with this. The following functions are the functions that draws the map unto the panel and the function that draws the images unto the map. Am I doing something wrong here???

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void loadBImage(){
  3.         bImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 
  4.                 BufferedImage.TYPE_INT_RGB);
  5.         bImage2 = new BufferedImage(image.getWidth(null), image.getHeight(null), 
  6.                 BufferedImage.TYPE_INT_RGB);
  7.         Graphics bImageG = bImage.getGraphics();
  8.         Graphics bImage2 = bImage.getGraphics();
  9.         bImageG.drawImage(image, 0,0,null, null);
  10.         bImage2.drawImage(image, 0,0,null, null);
  11.     }
  12.  
  13. public void drawCard(int ax, int ay){
  14.         Graphics g = this.getGraphics();
  15.         g.setColor(new Color(150, 150, 150));
  16.         g.fillRect(ax, ay, 10, 10);
  17.     }
  18.  
  19. public void drawArmy(Country country, Player player){
  20.         country = currentCountry;
  21.         int xLoc = country.getXLoc();
  22.         int yLoc = country.getYLoc();
  23.         if (xLoc == 0){
  24.             xLoc = x;
  25.             country.setXLoc(x);
  26.         }
  27.         if (yLoc == 0){
  28.             yLoc = y;
  29.             country.setYLox(y);
  30.         }
  31.  
  32.         int numArmies = country.getNumArmies();
  33.         char armies = (char)(numArmies + '0');
  34.         char army[] = {armies};
  35.  
  36.         Graphics g = this.getGraphics();
  37.         String color = player.getColor();
  38.         Color aColor = null;
  39.         if (color == "Red"){
  40.             aColor = Color.RED;
  41.         }
  42.         else if (color == "Yellow"){
  43.             aColor = Color.YELLOW;
  44.         }
  45.         else if (color == "Blue"){
  46.             aColor = Color.BLUE;
  47.         }
  48.         else if (color == "Green"){
  49.             aColor = Color.GREEN;
  50.         }
  51.         else if (color == "Gray"){
  52.             aColor = Color.GRAY;
  53.         }
  54.         else if (color == "Orange"){
  55.             aColor = Color.ORANGE;
  56.         }
  57.         g.setColor(aColor);
  58.         g.fillOval(xLoc, yLoc, 10, 10);
  59.  
  60.         Color black = Color.BLACK;
  61.         g.setColor(black);
  62.         g.drawChars(army, 0, 1, xLoc, yLoc);
  63.     }
  64.  
  65. public void paintComponent(Graphics g) {
  66.         super.paintComponent(g);
  67.         if (!panelSized) {
  68.             scaleImage(getWidth(), getHeight());
  69.             loadBImage();
  70.             panelSized = true;
  71.         }
  72.         g.drawImage(bImage, 0, 0, image.getWidth(null), image.getHeight(null), this);
  73.  
  74.     }
  75.  
  76.  
Nov 27 '07 #1
0 858

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
1
by: zengou | last post by:
My application have many picturebox objects,when run it ,sometimes i will have a strange error,how to work out ,help me please!(in windows98,the error cause frequently than in windowsxp) ...
4
by: funcSter | last post by:
Hey, got a prob which is driving me nuts! I'm trying to resize the resolution of an image as well as it's pyhsical byte size. I've got: byte bytImage = null; System.Drawing.Image imgImage =...
2
by: billy | last post by:
I'm working on a sort of paint program that has the usual canvas pane in the middle of the main form. I'm working on that class and have a couple quick questions.. actually more like I'm looking...
3
by: anastasia | last post by:
I get an out of memory exception when attempting to excecute the following code: original = System.Drawing.Image.FromFile(file.FileName,true); I ONLY get this exception when the file is in the...
7
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as...
2
by: George | last post by:
Dear colleagues, I refer to your help with specific graphic problem. It is necessary to create a viewfinder in graphic application. It seems that the algorithm is simple: just draw lines in...
7
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
1
by: saadkhan | last post by:
please help me that how could i be able to save images in an array. I have made an array like: System.Drawing.Image arr = new System.Drawing.Image; But i have no idea how to save different images...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.