怎样获得JPG、TIFF图象的分辨率(DPI),我出500分! ( 积分: 100 )

  • 主题发起人 主题发起人 zhengyong7381
  • 开始时间 开始时间
Z

zhengyong7381

Unregistered / Unconfirmed
GUEST, unregistred user!
我要获得、修改(DPI和像素)TIFF、JPG的DPI,像在PHOTOSHOP中显示的那样。
 
我要获得、修改(DPI和像素)TIFF、JPG的DPI,像在PHOTOSHOP中显示的那样。
 
用第三方图像控件可以。
 
给我500分再把把你的邮件地址发给我,我把原码发给你!
 
jieking,如果还能获得TIFF的DPI,我愿意把500分给你。
 
jieking,我的邮箱为zhengyong7381@sina.com
我怎么给你加上分呢?
 
好,帮顶



--------签名档---------------------------

比肩国内顶尖源码下载站点 -> 源码我爱你

http://www.source520.com
http://www.source520.net

80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
******************************************************************
附:为了站点持续发展,现有本站近年来收藏的大量大型商业源码低价出售,
详情请进入以下链接查看:
http://www.source520.com/building_delphi.htm

浏览商业代码请从如下URL进入查看实物:
1.商业源码库1: ftp://source520see3:browse@61.152.199.245/
2.商业源码库2: ftp://source520see2:browse@61.152.199.245/
 
解决没有?
 
真给还是假给。、
这是jpg图象设置x和y方向上的分辨率代码:
procedure SetJpgdpi(filename: string; dpix, dpiy: Integer);
const
BufferSize = 50;
DPI = 1; {inch}
DPC = 2; {cm}
var
Buffer: string;
index: Integer;
FileStream: TFileStream;
xResolution: WORD;
yResolution: WORD;
typeA: Byte;
begin
FileStream := TFileStream.Create(filename, fmOpenReadWrite);
try
SetLength(Buffer, BufferSize);
FileStream.Read(buffer[1], BufferSize);
index := Pos('JFIF' + #$00, buffer);
if index > 0 then
begin
FileStream.Seek(index + 6, soFromBeginning);
typeA := DPI;
FileStream.write(typeA, 1);
xresolution := swap(dpix);
FileStream.write(xresolution, 2);
yresolution := swap(dpiy);
FileStream.write(yresolution, 2);
end
finally
FileStream.Free;
end;
end;
 
看看这个单元:
{
Special thanks to
- Peter Schütt, Sahler GmbH, Bonn, schuett@sahler.de
for Bug fixes, 16 - Bit - Version and the Stream functions
- Nick Spurrier (MoDESoft, UK), nick@mode.co.uk
for 32-bit images
}

unit Bmp2Tiff;

interface

uses WinProcs, WinTypes, Classes, Graphics, ExtCtrls;

type
PDirEntry = ^TDirEntry;
TDirEntry = record
_Tag: Word;
_Type: Word;
_Count: LongInt;
_Value: LongInt;
end;

procedure WriteTiffToStream(Stream: TStream; Bitmap: TBitmap);
procedure WriteTiffToFile(Filename: string; Bitmap: TBitmap);

{$IFDEF WINDOWS}
const
{$ELSE}
var
{$ENDIF}
{ TIFF File Header: }
TifHeader: array[0..7] of Byte = (
$49, $49, { Intel byte order }
$2A, $00, { TIFF version (42) }
$08, $00, $00, $00); { Pointer to the first directory }

NoOfDirs: array[0..1] of Byte = ($0F, $00);
{ Number of tags within the directory }

DirectoryBW: array[0..13] of TDirEntry = (
(_Tag: $00FE; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ NewSubFile: Image with full solution (0) }
(_Tag: $0100; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageWidth: Value will be set later }
(_Tag: $0101; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageLength: Value will be set later }
(_Tag: $0102; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ BitsPerSample: 1 }
(_Tag: $0103; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ Compression: No compression }
(_Tag: $0106; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ PhotometricInterpretation: 0, 1 }
(_Tag: $0111; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripOffsets: Ptr to the adress of the image data }
(_Tag: $0115; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ SamplesPerPixels: 1 }
(_Tag: $0116; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ RowsPerStrip: Value will be set later }
(_Tag: $0117; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripByteCounts: xs*ys bytes pro strip }
(_Tag: $011A; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ X-Resolution: Adresse }
(_Tag: $011B; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ Y-Resolution: (Adresse) }
(_Tag: $0128; _Type: $0003; _Count: $00000001; _Value: $00000002),
{ Resolution Unit: (2)= Unit ZOLL }
(_Tag: $0131; _Type: $0002; _Count: $0000000A; _Value: $00000000));
{ Software: }

DirectoryCOL: array[0..14] of TDirEntry = (
(_Tag: $00FE; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ NewSubFile: Image with full solution (0) }
(_Tag: $0100; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageWidth: Value will be set later }
(_Tag: $0101; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageLength: Value will be set later }
(_Tag: $0102; _Type: $0003; _Count: $00000001; _Value: $00000008),
{ BitsPerSample: 4 or 8 }
(_Tag: $0103; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ Compression: No compression }
(_Tag: $0106; _Type: $0003; _Count: $00000001; _Value: $00000003),
{ PhotometricInterpretation: 3 }
(_Tag: $0111; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripOffsets: Ptr to the adress of the image data }
(_Tag: $0115; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ SamplesPerPixels: 1 }
(_Tag: $0116; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ RowsPerStrip: Value will be set later }
(_Tag: $0117; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripByteCounts: xs*ys bytes pro strip }
(_Tag: $011A; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ X-Resolution: Adresse }
(_Tag: $011B; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ Y-Resolution: (Adresse) }
(_Tag: $0128; _Type: $0003; _Count: $00000001; _Value: $00000002),
{ Resolution Unit: (2)= Unit ZOLL }
(_Tag: $0131; _Type: $0002; _Count: $0000000A; _Value: $00000000),
{ Software: }
(_Tag: $0140; _Type: $0003; _Count: $00000300; _Value: $00000008));
{ ColorMap: Color table startadress }

DirectoryRGB: array[0..14] of TDirEntry = (
(_Tag: $00FE; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ NewSubFile: Image with full solution (0) }
(_Tag: $0100; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageWidth: Value will be set later }
(_Tag: $0101; _Type: $0003; _Count: $00000001; _Value: $00000000),
{ ImageLength: Value will be set later }
(_Tag: $0102; _Type: $0003; _Count: $00000003; _Value: $00000008),
{ BitsPerSample: 8 }
(_Tag: $0103; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ Compression: No compression }
(_Tag: $0106; _Type: $0003; _Count: $00000001; _Value: $00000002),
{ PhotometricInterpretation:
0=black, 2 power BitsPerSample -1 =white }
(_Tag: $0111; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripOffsets: Ptr to the adress of the image data }
(_Tag: $0115; _Type: $0003; _Count: $00000001; _Value: $00000003),
{ SamplesPerPixels: 3 }
(_Tag: $0116; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ RowsPerStrip: Value will be set later }
(_Tag: $0117; _Type: $0004; _Count: $00000001; _Value: $00000000),
{ StripByteCounts: xs*ys bytes pro strip }
(_Tag: $011A; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ X-Resolution: Adresse }
(_Tag: $011B; _Type: $0005; _Count: $00000001; _Value: $00000000),
{ Y-Resolution: (Adresse) }
(_Tag: $011C; _Type: $0003; _Count: $00000001; _Value: $00000001),
{ PlanarConfiguration:
Pixel data will be stored continous }
(_Tag: $0128; _Type: $0003; _Count: $00000001; _Value: $00000002),
{ Resolution Unit: (2)= Unit ZOLL }
(_Tag: $0131; _Type: $0002; _Count: $0000000A; _Value: $00000000));
{ Software: }

NullString: array[0..3] of Byte = ($00, $00, $00, $00);
X_Res_Value: array[0..7] of Byte = ($6D, $03, $00, $00, $0A, $00, $00, $00);
{ Value for X-Resolution:
87,7 Pixel/Zoll (SONY SCREEN) }
Y_Res_Value: array[0..7] of Byte = ($6D, $03, $00, $00, $0A, $00, $00, $00);
{ Value for Y-Resolution: 87,7 Pixel/Zoll }
Software: array[0..9] of Char = ('K', 'r', 'u', 'w', 'o', ' ', 's', 'o', 'f',
't');
BitsPerSample: array[0..2] of Word = ($0008, $0008, $0008);

implementation

procedure WriteTiffToStream(Stream: TStream; Bitmap: TBitmap);
var
BM: HBitmap;
Header, Bits: PChar;
BitsPtr: PChar;
TmpBitsPtr: PChar;
HeaderSize: {$IFDEF WINDOWS}INTEGER{$ELSE}DWORD{$ENDIF};
BitsSize: {$IFDEF WINDOWS}LongInt{$ELSE}DWORD{$ENDIF};
Width, Height: {$IFDEF WINDOWS}LongInt{$ELSE}Integer{$ENDIF};
DataWidth: {$IFDEF WINDOWS}LongInt{$ELSE}Integer{$ENDIF};
BitCount: {$IFDEF WINDOWS}LongInt{$ELSE}Integer{$ENDIF};
ColorMapRed: array[0..255, 0..1] of Byte;
ColorMapGreen: array[0..255, 0..1] of Byte;
ColorMapBlue: array[0..255, 0..1] of Byte;
ColTabSize: Integer;
I, K: {$IFDEF WINDOWS}LongInt{$ELSE}Integer{$ENDIF};
Red, Blue: Char;
{$IFDEF WINDOWS}
RGBArr: packed array[0..2] of CHAR;
{$ENDIF}
BmpWidth: {$IFDEF WINDOWS}LongInt{$ELSE}Integer{$ENDIF};
OffsetXRes: LongInt;
OffsetYRes: LongInt;
OffsetSoftware: LongInt;
OffsetStrip: LongInt;
OffsetDir: LongInt;
OffsetBitsPerSample: LongInt;
{$IFDEF WINDOWS}
MemHandle: THandle;
MemStream: TMemoryStream;
ActPos, TmpPos: LongInt;
{$ENDIF}
begin
BM := Bitmap.Handle;
if BM = 0 then
exit;

GetDIBSizes(BM, HeaderSize, BitsSize);
{$IFDEF WINDOWS}
MemHandle := GlobalAlloc(HeapAllocFlags, HeaderSize + BitsSize);
Header := GlobalLock(MemHandle);
MemStream := TMemoryStream.Create;
{$ELSE}
GetMem(Header, HeaderSize + BitsSize);
{$ENDIF}
try
Bits := Header + HeaderSize;
if GetDIB(BM, Bitmap.Palette, Header^, Bits^) then
begin
{ Read Image description }
Width := PBITMAPINFO(Header)^.bmiHeader.biWidth;
Height := PBITMAPINFO(Header)^.bmiHeader.biHeight;
BitCount := PBITMAPINFO(Header)^.bmiHeader.biBitCount;

{$IFDEF WINDOWS}
{ Read Bits into MemoryStream for 16 - Bit - Version }
MemStream.Write(Bits^, BitsSize);
{$ENDIF}

{ Count max No of Colors }
ColTabSize := (1 shl BitCount);
BmpWidth := Trunc(BitsSize / Height);

{ ========================================================================== }
{ 1 Bit - Bilevel-Image }
{ ========================================================================== }
if BitCount = 1 then // Monochrome Images
begin
DataWidth := ((Width + 7) div 8);

DirectoryBW[1]._Value := LongInt(Width); { Image Width }
DirectoryBW[2]._Value := LongInt(abs(Height)); { Image Height }
DirectoryBW[8]._Value := LongInt(abs(Height)); { Rows per Strip }
DirectoryBW[9]._Value := LongInt(DataWidth * abs(Height));
{ Strip Byte Counts }

{ Write TIFF - File for Bilevel-Image }
{-------------------------------------}
{ Write Header }
Stream.Write(TifHeader, sizeof(TifHeader));

OffsetStrip := Stream.Position;
{ Write Image Data }

if Height < 0 then
begin
for I := 0 to Height - 1 do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + I * BmpWidth;
Stream.Write(BitsPtr^, DataWidth);
{$ELSE}
MemStream.Position := I * BmpWidth;
Stream.CopyFrom(MemStream, DataWidth);
{$ENDIF}
end;
end
else
begin
{ Flip Image }
for I := 1 to Height do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + (Height - I) * BmpWidth;
Stream.Write(BitsPtr^, DataWidth);
{$ELSE}
MemStream.Position := (Height - I) * BmpWidth;
Stream.CopyFrom(MemStream, DataWidth);
{$ENDIF}
end;
end;

OffsetXRes := Stream.Position;
Stream.Write(X_Res_Value, sizeof(X_Res_Value));

OffsetYRes := Stream.Position;
Stream.Write(Y_Res_Value, sizeof(Y_Res_Value));

OffsetSoftware := Stream.Position;
Stream.Write(Software, sizeof(Software));

{ Set Adresses into Directory }
DirectoryBW[6]._Value := OffsetStrip; { StripOffset }
DirectoryBW[10]._Value := OffsetXRes; { X-Resolution }
DirectoryBW[11]._Value := OffsetYRes; { Y-Resolution }
DirectoryBW[13]._Value := OffsetSoftware; { Software }

{ Write Directory }
OffsetDir := Stream.Position;
Stream.Write(NoOfDirs, sizeof(NoOfDirs));
Stream.Write(DirectoryBW, sizeof(DirectoryBW));
Stream.Write(NullString, sizeof(NullString));

{ Update Start of Directory }
Stream.Seek(4, soFromBeginning);
Stream.Write(OffsetDir, sizeof(OffsetDir));
end;

{ ========================================================================== }
{ 4, 8, 16 Bit - Image with Color Table }
{ ========================================================================== }
if BitCount in [4, 8, 16] then
begin
DataWidth := Width;
if BitCount = 4 then
begin
{ If we have only 4 bit per pixel, we have to
truncate the size of the image to a byte boundary }
Width := (Width div BitCount) * BitCount;
if BitCount = 4 then
DataWidth := Width div 2;
end;

DirectoryCOL[1]._Value := LongInt(Width); { Image Width }
DirectoryCOL[2]._Value := LongInt(abs(Height)); { Image Height }
DirectoryCOL[3]._Value := LongInt(BitCount); { BitsPerSample }
DirectoryCOL[8]._Value := LongInt(Height); { Image Height }
DirectoryCOL[9]._Value := LongInt(DataWidth * abs(Height));
{ Strip Byte Counts }

for I := 0 to ColTabSize - 1 do
begin
ColorMapRed[1] := PBITMAPINFO(Header)^.bmiColors.rgbRed;
ColorMapRed[0] := 0;
ColorMapGreen[1] :=
PBITMAPINFO(Header)^.bmiColors.rgbGreen;
ColorMapGreen[0] := 0;
ColorMapBlue[1] := PBITMAPINFO(Header)^.bmiColors.rgbBlue;
ColorMapBlue[0] := 0;
end;

DirectoryCOL[14]._Count := LongInt(ColTabSize * 3);

{ Write TIFF - File for Image with Color Table }
{----------------------------------------------}
{ Write Header }
Stream.Write(TifHeader, sizeof(TifHeader));
Stream.Write(ColorMapRed, ColTabSize * 2);
Stream.Write(ColorMapGreen, ColTabSize * 2);
Stream.Write(ColorMapBlue, ColTabSize * 2);

OffsetXRes := Stream.Position;
Stream.Write(X_Res_Value, sizeof(X_Res_Value));

OffsetYRes := Stream.Position;
Stream.Write(Y_Res_Value, sizeof(Y_Res_Value));

OffsetSoftware := Stream.Position;
Stream.Write(Software, sizeof(Software));

OffsetStrip := Stream.Position;
{ Write Image Data }
if Height < 0 then
begin
for I := 0 to Height - 1 do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + I * BmpWidth;
Stream.Write(BitsPtr^, DataWidth);
{$ELSE}
MemStream.Position := I * BmpWidth;
Stream.CopyFrom(MemStream, DataWidth);
{$ENDIF}
end;
end
else
begin
{ Flip Image }
for I := 1 to Height do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + (Height - I) * BmpWidth;
Stream.Write(BitsPtr^, DataWidth);
{$ELSE}
MemStream.Position := (Height - I) * BmpWidth;
Stream.CopyFrom(MemStream, DataWidth);
{$ENDIF}
end;
end;

{ Set Adresses into Directory }
DirectoryCOL[6]._Value := OffsetStrip; { StripOffset }
DirectoryCOL[10]._Value := OffsetXRes; { X-Resolution }
DirectoryCOL[11]._Value := OffsetYRes; { Y-Resolution }
DirectoryCOL[13]._Value := OffsetSoftware; { Software }

{ Write Directory }
OffsetDir := Stream.Position;
Stream.Write(NoOfDirs, sizeof(NoOfDirs));
Stream.Write(DirectoryCOL, sizeof(DirectoryCOL));
Stream.Write(NullString, sizeof(NullString));

{ Update Start of Directory }
Stream.Seek(4, soFromBeginning);
Stream.Write(OffsetDir, sizeof(OffsetDir));
end;

if BitCount in [24, 32] then
begin

{ ========================================================================== }
{ 24, 32 - Bit - Image with with RGB-Values }
{ ========================================================================== }
DirectoryRGB[1]._Value := LongInt(Width); { Image Width }
DirectoryRGB[2]._Value := LongInt(Height); { Image Height }
DirectoryRGB[8]._Value := LongInt(Height); { Image Height }
DirectoryRGB[9]._Value := LongInt(3 * Width * Height);
{ Strip Byte Counts }

{ Write TIFF - File for Image with RGB-Values }
{ ------------------------------------------- }
{ Write Header }
Stream.Write(TifHeader, sizeof(TifHeader));

OffsetXRes := Stream.Position;
Stream.Write(X_Res_Value, sizeof(X_Res_Value));

OffsetYRes := Stream.Position;
Stream.Write(Y_Res_Value, sizeof(Y_Res_Value));

OffsetBitsPerSample := Stream.Position;
Stream.Write(BitsPerSample, sizeof(BitsPerSample));

OffsetSoftware := Stream.Position;
Stream.Write(Software, sizeof(Software));

OffsetStrip := Stream.Position;

{ Exchange Red and Blue Color-Bits }
for I := 0 to Height - 1 do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + I * BmpWidth;
{$ELSE}
MemStream.Position := I * BmpWidth;
{$ENDIF}
for K := 0 to Width - 1 do
begin
{$IFNDEF WINDOWS}
Blue := (BitsPtr)^;
Red := (BitsPtr + 2)^;
(BitsPtr)^ := Red;
(BitsPtr + 2)^ := Blue;
if BitCount = 24 then
BitsPtr := BitsPtr + 3 // 24 - Bit Images
else
BitsPtr := BitsPtr + 4; // 32 - Bit images
{$ELSE}
MemStream.Read(RGBArr, SizeOf(RGBArr));
MemStream.Seek(-SizeOf(RGBArr), soFromCurrent);
Blue := RGBArr[0];
Red := RGBArr[2];
RGBArr[0] := Red;
RGBArr[2] := Blue;
MemStream.Write(RGBArr, SizeOf(RGBArr));
if BitCount = 32 then
MemStream.Seek(1, soFromCurrent);
{$ENDIF}
end;
end;

// If we have 32-Bit Image: skip every 4-th pixel
if BitCount = 32 then
begin
for I := 0 to Height - 1 do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + I * BmpWidth;
TmpBitsPtr := BitsPtr;
{$ELSE}
MemStream.Position := I * BmpWidth;
ActPos := MemStream.Position;
TmpPos := ActPos;
{$ENDIF}
for k := 0 to Width - 1 do
begin
{$IFNDEF WINDOWS}
(TmpBitsPtr)^ := (BitsPtr)^;
(TmpBitsPtr + 1)^ := (BitsPtr + 1)^;
(TmpBitsPtr + 2)^ := (BitsPtr + 2)^;
TmpBitsPtr := TmpBitsPtr + 3;
BitsPtr := BitsPtr + 4;
{$ELSE}
MemStream.Seek(ActPos, soFromBeginning);
MemStream.Read(RGBArr, SizeOf(RGBArr));
MemStream.Seek(TmpPos, soFromBeginning);
MemStream.Write(RGBArr, SizeOf(RGBArr));
TmpPos := TmpPos + 3;
ActPos := ActPos + 4;
{$ENDIF}
end;
end;
end;

{ Write Image Data }
if Height < 0 then
begin
BmpWidth := Trunc(BitsSize / Height);
for I := 0 to Height - 1 do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + I * BmpWidth;
Stream.Write(BitsPtr^, Width * 3);
{$ELSE}
MemStream.Position := I * BmpWidth;
Stream.CopyFrom(MemStream, Width * 3);
{$ENDIF}
end;
end
else
begin
{ Write Image Data and Flip Image horizontally }
BmpWidth := Trunc(BitsSize / Height);
for I := 1 to Height do
begin
{$IFNDEF WINDOWS}
BitsPtr := Bits + (Height - I) * BmpWidth;
Stream.Write(BitsPtr^, Width * 3);
{$ELSE}
MemStream.Position := (Height - I) * BmpWidth;
Stream.CopyFrom(MemStream, Width * 3);
{$ENDIF}
end;
end;

{ Set Offset - Adresses into Directory }
DirectoryRGB[3]._Value := OffsetBitsPerSample; { BitsPerSample }
DirectoryRGB[6]._Value := OffsetStrip; { StripOffset }
DirectoryRGB[10]._Value := OffsetXRes; { X-Resolution }
DirectoryRGB[11]._Value := OffsetYRes; { Y-Resolution }
DirectoryRGB[14]._Value := OffsetSoftware; { Software }

{ Write Directory }
OffsetDir := Stream.Position;
Stream.Write(NoOfDirs, sizeof(NoOfDirs));
Stream.Write(DirectoryRGB, sizeof(DirectoryRGB));
Stream.Write(NullString, sizeof(NullString));

{ Update Start of Directory }
Stream.Seek(4, soFromBeginning);
Stream.Write(OffsetDir, sizeof(OffsetDir));
end;
end;
finally
{$IFDEF WINDOWS}
GlobalUnlock(MemHandle);
GlobalFree(MemHandle);
MemStream.Free;
{$ELSE}
FreeMem(Header);
{$ENDIF}
end;
end;

(*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*)

procedure WriteTiffToFile(Filename: string; Bitmap: TBitmap);
var
Stream: TFileStream;
begin
Stream := TFileStream.Create(FileName, fmCreate);
try
WriteTiffToStream(Stream, Bitmap);
finally
Stream.Free;
end;
end;

end.
 
{来自:hzjone, 时间:2005-12-8 9:31:44, ID:3289575
真给还是假给。、
这是jpg图象设置x和y方向上的分辨率代码:}

反了呀,他要的是得到JPG分辨率(DPI),不是设置。
 
const
BufferSize = 50;
var
Buffer: string;
index: Integer;
FileStream: TFileStream;
xResolution: WORD;
yResolution: WORD;
_type: Byte;
begin
FileStream := TFileStream.Create('d:/logo.jpg', fmOpenReadWrite);
try
SetLength(Buffer, BufferSize);
FileStream.Read(buffer[1], BufferSize);
index := Pos('JFIF' + #$00, buffer);
if index > 0 then
begin
FileStream.Seek(index + 6, soFromBeginning);
FileStream.Read(_type, 2);
showmessage(inttostr(_type)); //分辨率单位:0:无单位,1:点数/英寸,2:点数/厘米
filestream.Read(xresolution,2); //水平分辨率
FileStream.Read(yresolution, 2); //垂直分辨率
showmessage(inttostr(xResolution)+';'+inttostr(yresolution));
end
finally
FileStream.Free;
end;
end;
 
为什么大家都是jpg的,为什么没有TIFF的呢,我最需要的就是TIFF,大家回答了这个问题,我就开始发分拉!
 
哎 TIFF 很复杂啊,因为他格式是不确定的。。。。。。我查了查资料
只看到了在图象入口偏移256个字节开始,存的图象信息:

TagName Decimal Hex Type Value
ImageWidth 256 100 SHORT or LONG
ImageLength 257 101 SHORT or LONG
Compression 259 103 SHORT 1, 2 or 32773
PhotometricInterpretation 262 106 SHORT 0 or 1
StripOffsets 273 111 SHORT or LONG
RowsPerStrip 278 116 SHORT or LONG
StripByteCounts 279 117 LONG or SHORT
XResolution 282 11A RATIONAL
YResolution 283 11B RATIONAL
ResolutionUnit 296 128 SHORT 1, 2 or 3

上面是我从tiff格式说明书上抄的,可惜是全英文。。。我英语太差 没看懂。。
你要是要,告诉我邮箱地址 我发一份给你

另外你看看这篇文章,是用VC写的如何读取TIF文件,应该对你有帮助
http://www.vckbase.com/document/viewdoc/?id=1569
 
TmgTemp : TImage;
PicWidth, PicHeight : integer;
ImgTemp := TImage.Create(Application);
ImgTemp.Picture.LoadFromFile('c:/Pic.jpg');
PicWidth := ImgTemp.Picture.Bitmap.Width;
PicHeight := ImgTemp.Picture.Bitmap.Height;

将PicWidth * PicHeight相乘就是你要的分辨率
 
JPG格式分辨率是存在文件头部有8位二进制组成,但是TIF可就不一样了,他是可变的不是存在文件统一地址的,我为这个文件足足花了半年时间,500分加给我,我把原码发给你!
 
jieking,我的邮箱为zhengyong7381@sina.com
我怎么给你加上分呢?给我发了,我一定加。
 
我是楼主就绝对不会被挟或者抢劫地送分出去,像tif jpg这样流行的图像格式,在网上搜索一下就一大堆,这些人为的格式,根本不需要自己去研究去发现。
 
kinneng你说的轻巧,你去给我找啊,我照样放分给你!
 
楼主看看hs-kill给的链接,里面有tif的文件头格式。

IFD是TIF图中最重要的数据结构,它包含了一个TIF文件中最重要的信息,一个TIF图可能有多个IFD,这说明文件中有多个图像,每个IFD标识1个图像的基本属性。 IFD结构中包含了三类成员,Directory Entry Count指出该结构里面有多少个目录入口;接下来就是N个线性排列的DE序列,数量不定(这就是 为什么称TIF格式文件为可扩充标记的文件,甚至用户可以添加自定义的标记属性),每个DE标识了图像的某一个属性;最后就是一个偏移量, 标识下一个文件目录相对于文件开始处的位置,当然,如果该TIF文件只包含了一幅图像,那么就只有一个IFD,显然,这个偏移量就等于0。
一个DE就是一幅图像的某一个属性。例如图像的大小、分辨率、是否压缩、像素的行列数。。。。。。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部