Converting Windows Bitmap to X bitmap format so that Tk can display it 
Author Message
 Converting Windows Bitmap to X bitmap format so that Tk can display it

Is there a tool to convert windows bitmap format to X format. I need this to
display the bitmap in tk.


Tue, 30 Dec 2003 18:33:34 GMT  
 Converting Windows Bitmap to X bitmap format so that Tk can display it

Quote:

> Is there a tool to convert windows bitmap format to X format. I need this to
> display the bitmap in tk.

Not exactly one tool, but some little helpers from the strimj family
(binary BMP images only, but that's what you asked for - for color it
would take some more work):

 namespace eval strimj {
     proc bitmap {si args} {eval [list image create bitmap -data [xbm
$si]] $args}
     proc expand {si {w 0} {h 0}} {
        #--- turn a strimj to specified dim. and equal-length lines
        if {!$w} {set w [width  $si]}
        if {!$h} {set h [height $si]}
        set res {}; set n 0; set filler " "
        foreach line [lines $si] {
            lappend res [pad line $w $filler]
            incr n
        }
        set filline [string repeat $filler $w]
        while {$n<$h} {lappend res $filline; incr n}
        join $res \n
    }
    proc fromBMP2  bmp {
        #-- make a strimj from a binary BMP image file
            set             fp [open $bmp]
            fconfigure     $fp -translation binary
            set data [read $fp [file size $bmp]]
            close          $fp
            set offset 62

            set nbytes [expr {(($width+31)/32)*4}] ;# 4-byte aligned
            set nbits  [expr {(($width+7)/8)*8}]   ;# byte-aligned
            set res ""
            for {set y [expr {$height-1}]} {$y>=0} {incr y -1} {

                append res [string range $line 0 [expr {$width-1}]]\n
            }

    }
    proc height si {llength [lines $si]}
    proc lines  si {split [string trim $si \n] \n}
    proc pad {_string length filler} {
        upvar $_string string
        set n [expr {$length-[string length $string]}]
        append string [string repeat $filler $n]
    }
    proc width si {util::max [util::map "string length" [lines $si]]}
    proc xbm si {
        set si [string map {" " 0 . 0} [expand $si]]
        set lines [lines $si]
        set width [string length [lindex $lines 0]]
        set height [llength $lines]
        set bytes {}
        foreach line $lines {
            regsub -all {[^0]} $line 1 line ;# black pixel
            foreach bin [split [binary format b* $line] ""] {
                    lappend bytes [scan $bin %c]
            }
        }
        set    res "#define i_width $width\n#define i_height $height\n"
        append res "static char i_bits\[\] = {\n[join $bytes ,]\n}"
    }

Quote:
}

 namespace eval util {
    proc map {func list} {
        #--- apply a function to each element of a list
        set res {}
        foreach i $list {lappend res [eval $func [list $i]]}
        set res
    }
    proc max args {
        if {[llength $args]==1} {set args [lindex $args 0]}
        lindex [lsort -real -decreasing $args] 0
    }
Quote:
}

#Usage example:
set filename ~/tcl/Schwabacher2.bmp ;# put your filename here
button .b -image [strimj::bitmap [strimj::fromBMP2 $filename]]
pack .b
--
Schoene Gruesse/best regards, Richard Suchenwirth - +49-7531-86 2703
Siemens Dematic AG, PA RC D2, Buecklestr.1-5, 78467 Konstanz,Germany
Personal opinions expressed only unless explicitly stated otherwise.


Tue, 30 Dec 2003 19:13:43 GMT  
 Converting Windows Bitmap to X bitmap format so that Tk can display it
Use the ImageMagick tools they do pretty match everything with images:
http://www.imagemagick.org/


Quote:
> Is there a tool to convert windows bitmap format to X format. I need this
to
> display the bitmap in tk.



Tue, 30 Dec 2003 19:18:30 GMT  
 Converting Windows Bitmap to X bitmap format so that Tk can display it

Quote:

>Is there a tool to convert windows bitmap format to X format. I need this to
>display the bitmap in tk.

xv, pnmtools, convert (from the ImageMagick package), gimp, ...

Salut,
       Bastien

--

MWG Biotech AG -- Anzinger Strasse 7a -- D-85560 Ebersberg; Germany
Phone: +49 8092 8289 309 -- Fax: +49 8092 8289 310



Wed, 31 Dec 2003 01:34:19 GMT  
 Converting Windows Bitmap to X bitmap format so that Tk can display it

  In a message on Fri, 13 Jul 2001 03:33:34 -0700, wrote :

"> Is there a tool to convert windows bitmap format to X format. I need this to
"> display the bitmap in tk.

Note: X11 bitmap really are bitmaps -- they are *one* bit deep!
MS-Windows 'bitmaps' are *color*, with 8 or 24 bits.  You should just
convert your bitmap to a GIF file.  Tcl/Tk can load in GIF files as
images (image create photo name -file foo.gif), which can be used as the
target of an -image option (label .foo -image name).

--
                                     \/


http://www.deepsoft.com              /\FidoNet:    1:321/153



Wed, 31 Dec 2003 08:32:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to Convert X Bitmap Format to Windows Bitmap Format?

2. Bitmap for icon != bitmap for button?

3. coloured bitmap with the option -bitmap ?

4. windows 3.0 bitmap reader in ST/V Windows

5. display a bitmap

6. Bitmap display in Visual Age

7. Help-How to Display a BitMap Image on a Report (Digitalk RW)

8. String display on top on bitmap image

9. Help: CL bitmap display (REXX?)

10. gtkada, how to display a bitmap picture?

11. problem with bitmap display

12. bitmap display?

 

 
Powered by phpBB® Forum Software