Click here to Skip to main content
15,923,689 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: how do you sort a list? Pin
nm_11411-Jun-04 13:47
nm_11411-Jun-04 13:47 
GeneralRe: how do you sort a list? Pin
geo_m11-Jun-04 23:41
geo_m11-Jun-04 23:41 
GeneralRe: how do you sort a list? Pin
nm_11412-Jun-04 10:11
nm_11412-Jun-04 10:11 
GeneralRe: how do you sort a list? - Solution for VC6! Pin
T.T.H.3-Aug-04 5:06
T.T.H.3-Aug-04 5:06 
QuestionNested STL maps? Pin
dbunder9-Jun-04 16:00
dbunder9-Jun-04 16:00 
AnswerRe: Nested STL maps? Pin
10-Jun-04 4:10
suss10-Jun-04 4:10 
AnswerRe: Nested STL maps? Pin
Paul Ranson10-Jun-04 4:42
Paul Ranson10-Jun-04 4:42 
GeneralCreateImage problem in java Pin
sriamar8-Jun-04 6:19
sriamar8-Jun-04 6:19 
Hi I am trying to extract image data from a binary file. I am new to
java and I am using eclipse in windows 2000.

there are a total of 9 images in the file out of which i am extracting
8.the images are littleendian.

The program always displays the last image. if i change
NUMOFIMAGES to 2 then it displays img[2] and if it is 7 displays
img[7] for all the images; Any ideas on this?



<br />
import java.io.*;<br />
import javax.swing.*;<br />
import java.awt.*;<br />
import java.awt.event.*;<br />
import java.awt.image.*;<br />
<br />
public class scanner3d extends JPanel {<br />
	static Image img[] = new Image[10];<br />
<br />
	public static void main(String[] args) throws IOException {<br />
		scanner3d scner = new scanner3d();<br />
		int WIDTH = 150;<br />
		int HEIGHT = 200;<br />
		int NUMOFIMAGES = 9;<br />
		<br />
		<br />
		try {<br />
			File file = new File("c:\\java\\15");<br />
			FileInputStream fileInput = new FileInputStream(file);<br />
//			similar to DataInputStream but reads little endian data.<br />
//			Available at http://mindprod.com/jgloss/ledatinputstream.html<br />
			LEDataInputStream ledatainputstream =<br />
				new LEDataInputStream(fileInput);<br />
			//DataInputStream dataIn =	new DataInputStream( fileInput );<br />
			float data[][][] = new float[NUMOFIMAGES][HEIGHT][WIDTH];<br />
			float max = 0;<br />
//			Reading the input file<br />
			for (int m = 0; m < NUMOFIMAGES; m++) {<br />
				for (int k = 0; k < HEIGHT; k++) {<br />
					for (int j = 0; j < WIDTH; j++) {<br />
						float in = ledatainputstream.readFloat();<br />
//						convert negative values to zero<br />
						if (in < 0)<br />
							in = 0;<br />
//						find the maximum value for scaling<br />
						if (in > max)<br />
							max = in;<br />
						data[m][k][j] = in; <br />
					}<br />
				}<br />
			}<br />
//			scale the Image<br />
			int OneDimImage[] = new int[WIDTH * HEIGHT];<br />
<br />
			for (int m = 0; m < NUMOFIMAGES; m++) {<br />
				for (int k = 0; k < HEIGHT; k++) {<br />
					for (int j = 0; j < WIDTH; j++) {<br />
						int temp = (int) (data[m][k][j] / max * 255);<br />
						int col = (255 << 24) | (temp << 16) | 0;<br />
						//if(j <= 5) col = (255 << 24) | (temp << 16) | 255;<br />
						OneDimImage[k * WIDTH + j] = col;<br />
					}<br />
				}<br />
				//crerating image<br />
					img[m] =<br />
						java.awt.Toolkit.getDefaultToolkit().createImage(<br />
							new MemoryImageSource(<br />
								WIDTH,<br />
								HEIGHT,<br />
								OneDimImage,<br />
								0,<br />
								WIDTH));<br />
								<br />
//				When this statements are "included" nothing is displayed.<br />
//				if they are commented out only the last image <br />
//				"img[7] is diaplayed" for all the images.<br />
//				It always displays the last image. if i change<br />
//				 NUMOFIMAGES to 2 then it displays img[2];  <br />
//				if ((m + 1) == NUMOFIMAGES)<br />
//					for (int k = 0; k < HEIGHT; k++) {<br />
//						for (int j = 0; j < WIDTH; j++) {<br />
//							OneDimImage[k * WIDTH + j] = -1;<br />
//						}<br />
//					}<br />
<br />
			}<br />
<br />
			JFrame f = new JFrame();<br />
			f.addWindowListener(new WindowAdapter() {<br />
				public void windowClosing(WindowEvent e) {<br />
					System.exit(0);<br />
				}<br />
			});<br />
			f.getContentPane().add(scner);<br />
			//f.setBounds(50,50,WIDTH,HEIGHT);<br />
			f.show();<br />
		} catch (Exception r) {<br />
			System.out.println(r);<br />
			System.exit(0);<br />
		}<br />
	}<br />
	public void paint(Graphics g) {<br />
		super.paint(g);<br />
		Dimension d = getSize();<br />
		Insets i = getInsets();<br />
		g.drawImage(img[0], 13, 15, 245, 190, this);<br />
		g.drawImage(img[1], 263, 15, 245, 190, this);<br />
		g.drawImage(img[2], 513, 15, 245, 190, this);<br />
		g.drawImage(img[3], 763, 15, 245, 190, this);<br />
		g.drawImage(img[4], 13, 211, 245, 190, this);<br />
		g.drawImage(img[5], 263, 211, 245, 190, this);<br />
		g.drawImage(img[6], 513, 211, 245, 190, this);<br />
		g.drawImage(img[7], 763, 211, 245, 190, this);<br />
	}<br />
} //  @jve:visual-info  decl-index=0 visual-constraint="10,10"<br />


Have Fun!!!
GeneralCSMTPConnection Authentication Pin
prasoon997-Jun-04 18:37
prasoon997-Jun-04 18:37 
GeneralRe: CSMTPConnection Authentication Pin
Mike Dimmick8-Jun-04 2:16
Mike Dimmick8-Jun-04 2:16 
GeneralSome WTL - to MFC conversion help Pin
Ajnstajn6-Jun-04 23:25
Ajnstajn6-Jun-04 23:25 
GeneralRe: Some WTL - to MFC conversion help Pin
Jason De Arte7-Jun-04 8:39
Jason De Arte7-Jun-04 8:39 
Questionhow to read from or write to a file in c++? Pin
lzh086-Jun-04 15:21
lzh086-Jun-04 15:21 
AnswerRe: how to read from or write to a file in c++? Pin
Derick Cyril Thomas6-Jun-04 16:55
Derick Cyril Thomas6-Jun-04 16:55 
GeneralComposite and Builder Dessign Patterns Pin
Arun AC6-Jun-04 7:29
Arun AC6-Jun-04 7:29 
GeneralRe: Composite and Builder Dessign Patterns Pin
valikac6-Jun-04 12:47
valikac6-Jun-04 12:47 
GeneralMenu Ownerdraw and WindowFromDC Pin
Derick Cyril Thomas6-Jun-04 2:28
Derick Cyril Thomas6-Jun-04 2:28 
GeneralRe: Menu Ownerdraw and WindowFromDC Pin
Jason De Arte6-Jun-04 14:14
Jason De Arte6-Jun-04 14:14 
GeneralRe: Menu Ownerdraw and WindowFromDC Pin
Derick Cyril Thomas6-Jun-04 16:50
Derick Cyril Thomas6-Jun-04 16:50 
Questionhow to use WTL in other IDE,e.g bc++? Pin
lzh085-Jun-04 22:51
lzh085-Jun-04 22:51 
GeneralActiveXcontrol with directX in clientwindow , how prevent drawing background color Pin
Vliegenthart5-Jun-04 0:40
Vliegenthart5-Jun-04 0:40 
GeneralATL experts, help! Navigating to a new page in an ATL Active X control Pin
mcase4-Jun-04 22:44
mcase4-Jun-04 22:44 
GeneralRe: ATL experts, help! Navigating to a new page in an ATL Active X control Pin
Jason De Arte6-Jun-04 7:28
Jason De Arte6-Jun-04 7:28 
GeneralGreat advice! Pin
mcase6-Jun-04 22:45
mcase6-Jun-04 22:45 
GeneralTo clarify Pin
mcase6-Jun-04 22:50
mcase6-Jun-04 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.