重分悬赏:代码转换

Qinriwei 2001-06-09 06:13:00
哪位老大能帮忙将下面的DELPHI代码转换成C、C++、VC、VB中的任一种,分决不吝啬(现只能给这么多,后面再补上)。
急用!!!
代码如下:

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 }

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: 8 }
( _Tag: $0103; _Type: $0003; _Count: $00000001; _Value: $00000001 ), { Compression: No compression }
( _Tag: $0106; _Type: $0003; _Count: $00000001; _Value: $00000003 ), { PhotometricInterpretation: }
( _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;
DataWidth := Width;
if BitCount = 1 then
begin
{$IFDEF WINDOWS}
GlobalUnlock ( MemHandle ) ;
GlobalFree ( MemHandle ) ;
MemStream.Free ;
{$ELSE}
FreeMem(Header);
{$ENDIF}
exit;
end;
{$IFDEF WINDOWS}
{ Read Bits into MemoryStream for 16 - Bit - Version }
MemStream.Write ( Bits^, BitsSize ) ;
{$ENDIF}

ColTabSize := (1 shl BitCount);
{ ColTabSize := 1;
for I:=1 to BitCount do ColTabSize := ColTabSize * 2; }
BmpWidth := Trunc(BitsSize / Height);

{
// Image with Color Table
//================================
}
if BitCount in [2, 4, 8] then
begin
DataWidth := Width;
if BitCount in [2, 4] then
begin
{ If we have only 2 or 4 bit per pixel, we have to
truncate the size of the image to a byte boundary }
Width := (Width div BitCount) * BitCount;
if BitCount = 2 then DataWidth := Width div 4;
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 }
DirectoryRGB[9]._Value := LongInt(BitsSize); { Strip Byte Counts }

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

DirectoryCOL[14]._Count := LongInt(ColTabSize*3*2);
end
else
{
// Image with RGB-Values
//======================
}
begin
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 }
end;
{ Write TIFF - File }

{ Write Image with Color Table
================================ }
if BitCount in [1, 2, 4, 8] then
begin
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 ;
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
else
begin
{ Write 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
else BitsPtr := BitsPtr + 4;
{$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;

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
{ Flip Image }
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 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.

...全文
113 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
windindance 2001-06-09
  • 打赏
  • 举报
回复
1 这是用DELPHI写的,要翻译只能翻译成BCB较方便。
2 你……一点PASCAL语法都不懂吗?:)很简单呀。
HashCodeWithJava 2001-06-09
  • 打赏
  • 举报
回复
我觉得你先把它翻译成汉字。
然后由汉字翻译成其它计算器语言.
V20150531版 1、重要!修复导航站与信息站之间帐户登录通行时被侵后台的漏洞。 全新V20150512版更新说明: 1、实现了数据的海量备份与恢复。大数据时,不再依靠帝国备份王等程序,后台轻松实现海量MySQL数据的备份与恢复。 2、实现了多地区城市支持!很多朋友都期待的功能。 3、实现了与162100网址导航程序、162100Wap导航(手机版导航)的用户对接,登录后帐户通行。 4、增加、完善了首页模板。 5、增加、完善了列表模式,特别完善了图文列表模式。 6、增加、完善了广告位。 7、升级了论坛编辑器。 8、升级了发帖的提交方式。 9、在首页图文推荐基础上,增加了用户自行购买图文展示。 10、完善了栏目隐藏。 11、更改了伪静态规则。 12、对程序结构、代码进行了大幅优化完善……,不一一赘述。   【程序简介】 1、“拒绝繁冗,选择简炼”,PHP MySQL作品,162100.com原创。 2、论坛、分类信息、文章系统三合一系统,多用网站建设。 3、MySQL分区、索引操作,快捷运行、高效承载。 5、强大的管理后台:无限级自由分类、风格模式转换、伪静态支持、文章审核、成员管理、群发邮件、支付宝收银…… 6、精炼的用户中心:头像在线生成、个人名片制作、文章管理、悬赏、收藏、短信、货币及信誉管理…… 7、所见即所得的162100editer论坛编辑器。 8、多管理员及版主支持。 9、栏目分类已预装完毕,可按照自己的需要修改设定。 10、轻松管理广告位。 11、浏览器测试IE6、IE8、360、Firefox、Chrome、Safari、Opera兼容。 12、更多精彩实用尽属162100FAIcode 【程序安装】 1、参看read.txt。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧