Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Compare two bitmap objects

        private bool PicsIdentical(Bitmap bmp1, Bitmap bmp2)
        {
            bool retVal = true;

            if (bmp1.Size != bmp2.Size)
                retVal = false;
            else
            {
                for (int x = 0; x < bmp1.Width; x++)
                {
                    for (int y = 0; y < bmp1.Height; y++)
                    {
                        if (bmp1.GetPixel(x, y) != bmp2.GetPixel(x, y))
                        {
                            retVal = false;
                            break;
                        }
                    }
                }
            }
            return retVal;
        }

Counting number of bitmaps in an mbm file

I continue my hacking on symbian mbm(multi-bitmap) format.
# a helping function
from struct import unpack
def readL(f, pos=None):
    if pos is not None:
        f.seek(pos)
    return unpack('L', f.read(4))[0]

# the real counting function
def mbm_count(mbm_file):
    f = open(mbm_file, 'rb')
    mbm_type = readL(f)
    if mbm_type == 0x10000041:  # mbm on ROM (Z:)
        return readL(f) 
    elif mbm_type == 0x10000037L:  # mbm on file (normal)
        return readL(f, readL(f, 16)) # read at trailer
    else:       # what type is it?
        return None

For example (you may try this on your phone)
>>> mbm_count('z:\\system\\data\\avkon.mbm')
503L
>>> mbm_count('E:\\system\\apps\\FExplorer\\FExplorer.mbm')
19L
>>>

Using Icon as Image

Pys60 1.1.3 have 2 differnt classes for graphics data.
Icon class represents icon (typically from .mbm file)
which can be put in ListBox for selection.
Image class represents a bigger image which can be
drawn upon. These 2 classes can't convert to/from
each other.

So, I create a library that read .mbm file and draw
an Image from the data there. So, you can make
an icon into an image (now only 1-bit icons).
the module can be downloaded from here
http://larndham.net/service/pys60/icon_image.py
from appuifw import *
import icon_image, e32

app.body = c = Canvas()
# choose a bitmap from plenty inside mbm (multi-bitmap)
icon = icon_image('z:\\system\\data\\avkon.mbm', 28) 
c.blit(icon)

e32.ao_sleep(10)  # 10 sec to end program

Look here for more information.
http://discussion.forum.nokia.com/forum/showthread.php?s=&threadid=63608
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS