Click here to Skip to main content
15,559,819 members
Home / Discussions / C#
   

C#

 
Questionwhy DataView.RowFilter run more solwer then DataTable.Select Pin
alonesword30-Jun-07 22:02
alonesword30-Jun-07 22:02 
Questionhow to move in records? Pin
s_nazari@yahoo.com30-Jun-07 21:52
s_nazari@yahoo.com30-Jun-07 21:52 
AnswerRe: how to move in records? Pin
Christian Graus30-Jun-07 22:22
mveChristian Graus30-Jun-07 22:22 
GeneralRe: how to move in records? Pin
Robert Rohde1-Jul-07 3:49
Robert Rohde1-Jul-07 3:49 
QuestionRead width & Height of jpeg file Pin
Alaric_30-Jun-07 21:52
professionalAlaric_30-Jun-07 21:52 
AnswerRe: Read width & Height of jpeg file Pin
Mazdak30-Jun-07 21:59
Mazdak30-Jun-07 21:59 
GeneralRe: Read width &amp Height of jpeg file Pin
Alaric_30-Jun-07 22:11
professionalAlaric_30-Jun-07 22:11 
AnswerRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 5:23
sitebuilderLuc Pattyn1-Jul-07 5: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 7:29
professionalAlaric_1-Jul-07 7:29 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 7:40
sitebuilderLuc Pattyn1-Jul-07 7:40 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 7:45
professionalAlaric_1-Jul-07 7:45 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 7:55
sitebuilderLuc Pattyn1-Jul-07 7:55 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 8:06
professionalAlaric_1-Jul-07 8:06 
GeneralRe: Read width & Height of jpeg file Pin
Luc Pattyn1-Jul-07 8:15
sitebuilderLuc Pattyn1-Jul-07 8:15 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 9:01
professionalAlaric_1-Jul-07 9:01 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 9:15
professionalAlaric_1-Jul-07 9:15 
GeneralRe: Read width & Height of jpeg file Pin
Alaric_1-Jul-07 10:14
professionalAlaric_1-Jul-07 10:14 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 10:20
sitebuilderLuc Pattyn1-Jul-07 10:20 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 14:29
professionalAlaric_1-Jul-07 14:29 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 14:35
professionalAlaric_1-Jul-07 14:35 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 14:50
professionalAlaric_1-Jul-07 14:50 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 15:06
sitebuilderLuc Pattyn1-Jul-07 15:06 
GeneralRe: Read width &amp; Height of jpeg file Pin
Luc Pattyn1-Jul-07 15:19
sitebuilderLuc Pattyn1-Jul-07 15:19 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 15:23
professionalAlaric_1-Jul-07 15:23 
GeneralRe: Read width &amp; Height of jpeg file Pin
Alaric_1-Jul-07 15:24
professionalAlaric_1-Jul-07 15: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.