打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How to save a TBitmap to a WBMP file.

How to save a TBitmap to a WBMP file.

Title: How to save a TBitmap to a WBMP file.

Question: I needed to save WBMP files for WAP applications. Here is the way I found to do it...

Answer:
Note that the bitmap contained in the TBitmap must be black and white.

Function BitmapToWBMP( Bmp : TBitmap; Filename : String ) : Boolean;
Var
    F       : File;
    Buf     : Array[ 0..256 ] Of Byte;
    BufLen  : LongInt;
    BPos    : LongInt;
    B       : LongInt;
    X       : LongInt;
    Y       : LongInt;
    Procedure Write_To_Header( L : LongInt );
    Var
        Extra : LongInt;
        B     : Byte;
    Begin
        Extra := 0;
        While L = 128 Do Begin
            Inc( Extra );
            Dec( l, 128 );
        End;
        If Extra  0 Then Begin
            B := 128 + Extra;
            BlockWrite( F, B, 1 );
        End;
        B := l;
        BlockWrite( F, B, 1 );
    End;
Begin
    Result := False;
    If Bmp = NIL Then EXIT;
    If Bmp.Empty Then EXIT;
    If Bmp.Width = 0 Then EXIT;
    If Bmp.Height = 0 Then EXIT;
    AssignFile( F, FileName );
    Rewrite( F, 1 );
    If IOResult  0 Then EXIT;
    BufLen := Bmp.Width Shr 3 + Byte( Bmp.Width And 7  0 );
    Write_To_Header( 0 );
    Write_To_Header( 0 );
    Write_To_Header( Bmp.Width );
    Write_To_Header( Bmp.Height );
    For Y := 0 To Bmp.Height - 1 Do Begin
        FillChar( Buf, SizeOf( Buf ), 0 );
        BPos := 0;
        B := 128;
        For X := 0 To Bmp.Width - 1 Do Begin
            If Bmp.Canvas.Pixels[ X, Y ]  clBlack Then Inc( Buf[ BPos ], B );
            If B  1 Then
                B := B Shr 1
            Else Begin
                B := 128;
                Inc( BPos );
            End;
        End;
        BlockWrite( F, Buf, BufLen );
    End;
    CloseFile( F );
    Result := True;
End;

Enjoy!


from: http://delphi.xcjc.net//viewthread.php?tid=46488



More Tips:


Torry's Delphi Pages

ImageDraw can render an image file (*.wbmp, *.gif, *.jpg, *.png, *.bmp, *.ico, and *.tiff) to the image format preferred by client mobile device. ImageDraw doesn't ...
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
用Delphi实现24位真彩色图标
Delphi缩略图读取
GIF动画制作大全
使用DELPHI对图片中的文字进行识别的过程(最简单实现)
delphi实现屏幕截图
GDI+ 在Delphi程序的应用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服