Click here to Skip to main content
15,892,480 members
Home / Discussions / C#
   

C#

 
Questionwhy DataView.RowFilter run more solwer then DataTable.Select Pin
alonesword30-Jun-07 21:02
alonesword30-Jun-07 21:02 
Questionhow to move in records? Pin
s_nazari@yahoo.com30-Jun-07 20:52
s_nazari@yahoo.com30-Jun-07 20:52 
AnswerRe: how to move in records? Pin
Christian Graus30-Jun-07 21:22
protectorChristian Graus30-Jun-07 21:22 
GeneralRe: how to move in records? Pin
Robert Rohde1-Jul-07 2:49
Robert Rohde1-Jul-07 2:49 
QuestionRead width & Height of jpeg file Pin
Alaric_30-Jun-07 20:52
professionalAlaric_30-Jun-07 20:52 
AnswerRe: Read width & Height of jpeg file Pin
Mazdak30-Jun-07 20:59
Mazdak30-Jun-07 20:59 
GeneralRe: Read width &amp Height of jpeg file Pin
Alaric_30-Jun-07 21:11
professionalAlaric_30-Jun-07 21:11 
AnswerRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 4:23
sitebuilderLuc Pattyn1-Jul-07 4:23 
Hi, the only way to get JPEG size without using Image class is by reading (part of) the
JPEG file yourself, as in the following code:

public static Size GetJpegImageSize(string filename) {
	FileStream stream=null;
	BinaryReader rdr=null;
	try {
		stream=File.OpenRead(filename);
		rdr=new BinaryReader(stream);
		// keep reading packets until we find one that contains Size info
		for(; ; ) {
			byte code=rdr.ReadByte();
			if(code!=0xFF) throw new ApplicationException(
					"Unexpected value in file "+filename);
			code=rdr.ReadByte();
			switch(code) {
				// filler byte
				case 0xFF:
					stream.Position--;
					break;
				// packets without data
				case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: 
				case 0xD5: case 0xD6: case 0xD7: case 0xD8: case 0xD9:
					break;
				// packets with size information
				case 0xC0: case 0xC1: case 0xC2: case 0xC3:
				case 0xC4: case 0xC5: case 0xC6: case 0xC7:
				case 0xC8: case 0xC9: case 0xCA: case 0xCB:
				case 0xCC: case 0xCD: case 0xCE: case 0xCF:
					ReadBEUshort(rdr);
					rdr.ReadByte();
					ushort h=ReadBEUshort(rdr);
					ushort w=ReadBEUshort(rdr);
					return new Size(w, h);
				// irrelevant variable-length packets
				default:
					int len=ReadBEUshort(rdr);
					stream.Position+=len-2;
					break;
			}
		}
	} finally {
		if(rdr!=null) rdr.Close();
		if(stream!=null) stream.Close();
	}
}

private static ushort ReadBEUshort(BinaryReader rdr) {
	ushort hi=rdr.ReadByte();
	hi<<=8;
	ushort lo=rdr.ReadByte();
	return (ushort)(hi|lo);
}


A JPEG file contains a lot of packets (with Hufman tables and everything).
The above code does not know much about JPEG, it simply tries to jump from one packet
to the next until it finds one with size info.

Smile | :)


GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 6:29
professionalAlaric_1-Jul-07 6:29 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 6:40
sitebuilderLuc Pattyn1-Jul-07 6:40 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 6:45
professionalAlaric_1-Jul-07 6:45 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 6:55
sitebuilderLuc Pattyn1-Jul-07 6:55 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 7:06
professionalAlaric_1-Jul-07 7:06 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 7:15
sitebuilderLuc Pattyn1-Jul-07 7:15 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 8:01
professionalAlaric_1-Jul-07 8:01 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 8:15
professionalAlaric_1-Jul-07 8:15 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 9:14
professionalAlaric_1-Jul-07 9:14 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 9:20
sitebuilderLuc Pattyn1-Jul-07 9:20 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 13:29
professionalAlaric_1-Jul-07 13:29 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 13:35
professionalAlaric_1-Jul-07 13:35 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 13:50
professionalAlaric_1-Jul-07 13:50 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 14:06
sitebuilderLuc Pattyn1-Jul-07 14:06 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 14:19
sitebuilderLuc Pattyn1-Jul-07 14:19 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 14:23
professionalAlaric_1-Jul-07 14:23 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 14:24
professionalAlaric_1-Jul-07 14:24 

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.