Re: VB3 is making my head spin!



In article <df2397$91u$1@xxxxxxxxxxxxxxxxxxxx>,
Mike Williams <Mike@xxxxxxxxxxxxxxxxx> wrote:
><no.addr@xxxxxx> wrote in message news:df1g9g$m05@xxxxxxxxxxxxxx
>
><no.addr@xxxxxx> wrote in message news:df1g9g$m05@xxxxxxxxxxxxxx
>
>> If it is easy [reading in a *.bmp file bit by bit in VB3
>> and displaying it pixel by pixel] tell me how.
>
>Certainly. There are loads of different ways of doing it. Presumably, going by what you have
>said in your previous messages, you would prefer a method that does not use any of the various
>API routines? Is that the case?

Well, I have learnt to use API now, and it really results in shorter
code than writing things yourselves. Like Frank said, external
routines are used in most languages, not just in VB. So, what I prefer
is relatively short code, but readable and easier to maintain (say ten
years from now).

>
>> From our point of view, compactness
>> of the code is more important than speed.
>
>Okay. That's fine. But why are you particularly interested in compactness of code? You can often
>speed things up (sometimes quite dramatically) by adding a bit more code, and for such tasks as
>reading bitmaps the overall size of the compiled code is not going to be very large anyway.

The reason is that we are not programmers, and would like to code to
be easy to understand and maintain even by the person who has not
written it. Compactness is some cases leads to very complicated logic,
and that too is not desirable, because although it may be very
creative to do such things, it becomes difficult for someone else to
understand what the other person tried to do.

>
>> Besides, this code could be separate from the main large code,
>> which would just call Shell convert_bmp_to_RLE.exe, where
>> the conversion program could be as ugly or inefficient as it may be.
>
>Yep. Shelling a second VB app is suitable in many cases, and it is an easy way of getting a sort
>of "multithreaded" program in VB. Your current requirement appears to be to create an 8 bit RLE
>compressed bitmap from an original 24 but full colour bitmap that is held on disk as a standard
>.bmp file. Is that the case?

I think this option is easier than writing a lot of code inside the
large program which would produce a RLE compressed bitmap.

Or perhaps you want to create an 8bit RLE encoded bitmap file from
>an original bitmap image that has been drawn into a VB Form or Picture Box at run time by your
>own VB program (in which case the colour depth of the original will be the same as the colour
>depth of the display on which your app is currently running). What colour depth are you running
>at by the way (32 bit full colour or 16 bit or whatever)?

All RGB (0 to 255, 0 to 255, 0 to 255) are in use for displaying on
the screen. For the picture, colour accuracy is not important (in most
cases).

>
>By the way, although I said "reading a bitmap file from disk pixel by pixel in VB3 is easy" I
>didn't necessarily mean that the entire job (creating an 8 bit RLE compressed bitmap from it)
>would also be easy.

I know this is not easy. Reading a bitmap pixel by pixel is easy and
years back I picked some code to do that.

Most of the steps are fairly easy, but the task of reducing the original
>colours (which may be half a million or more!) to a maximum of 256 in such a way that the
>picture looks as close to the original as possible can be quite complex.

Yes. However, to start with, a simple algorithm reducing the millions
of colours to 8 bits is enough. Some day, far in future, we will run
into situations where two curves in two different colours on the same
plot will appear in the same colour in the RLE compressed bmp. But, I
don't think this is a problem for years to come. Today, multiple
curves are plotted in 10 of the VBColor (0 to 15). The background
maps poorly to 8 bit, but that is not so important.

>
>In your case though you probably don't need to worry about that specific part of the task,
>because I imagine that your original drawing (as currently drawn to the Form or whatever by your
>exisiting VB3 app) actually contains fewer than 256 colours anyway (although of course the VB
>SavePicture method will save it as a bitmap which has the same colour depth of your display,
>which going by your previous messages seems to be full colour 24 bit).

Yes, it is.

If, as I suspect, your
>original drawn picture contains fewer than 256 colours then you can include all of the used
>colours in the new 8 bit bitmap file, and you can do it quite easily.

In the worst case, we have 12 colours; usually 4.

In either case, you can
>save the new 8bit bitmap using only standard VB File I/O and without using the VB SavePicture
>method. Post again with full details of what you are doing, what colour depth you are running at
>and how many colours there are in the "drawn" bitmap, and any other information that you think
>might be relevant.

There are 2 background colours, one colour for drawing a curve, and
black for text. On some other screens, upto 10 curves are shown in
different colours. Then there is one page where millions of colours
are always used, but it would be stupid to try to put that in RLE.

The job of creating an 8 bit RLE compressed bitmap from an existing full
>colour 24 bit bitmap can be done without using any API routines at all, which I think is what
>you are really after.

You have convinced me that API is not terribly evil, and I have
actually started using it since the last couple of weeks. Writing at
an angle is also going to need Create FontIndirect.

>
>Besides, using API routines does not guarantee success, and neither does it guarantee that you
>end up with fast code (although it helps of course).

At least for us, speed is not at all an issue.

As an example, have a look at the code on
>the following site. It shows you how to load a full colour 24bit .bmp file from disk and count
>the number of unique colours it contains (one of the tasks you will probably want to carry out
>in your own program). Download it and check it out.

I have actually done more complicated things than this, like edge
detection, blurring, watershed, etc. and know that image processing
algorithms can be made very slow to very fast depending on how they
are programmed.

>
>http://www.vbaccelerator.com/home/VB/Code/vbMedia/Image_Processing/Counting_Colours/article.asp
>

.



Relevant Pages

  • =?iso-8859-1?Q?Re:_CopyFromScreen_Bitmap_als_Bild_speichern_und_Gr=F6=DFe?= =?iso-8859&#
    ... wenn du mit der Auflösung festlegst, dass in einem Zoll 96 Pixel darzustellen sind, dann belegen 200 Pixel etwa 55 mm. ... Dim bmp As Bitmap = New Bitmap ... g.DrawImage(bmp, 0, 0, breite, hoehe) ... Wie Du erkennen kannst ist die Linke Grafik nur noch halb so breit wie die Obere, ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: count colors in bitmap
    ... But on my own two machines your code DOES crash on a 1024 x 768 bitmap! ... And it also DOES crashes on a 3200 x 2400 pixel bitmap. ... Why don't you just believe me, and check things out further yourself, perhaps on the machines of other people you might know, specifically on machines that might be differently configured and running different vesions of the OS than your own. ... Private Declare Function LoadImage Lib "user32" Alias _ ...
    (microsoft.public.vb.general.discussion)
  • Re: count colors in bitmap
    ... But on my own two machines your code DOES crash on a 1024 x 768 bitmap! ... And it also DOES crashes on a 3200 x 2400 pixel bitmap. ... on both of my own machines your app CRASHES on both a 1024 x 768 bitmap and on a 3200 x 2400 pixel bitmap. ... Private Declare Function LoadImage Lib "user32" Alias _ ...
    (microsoft.public.vb.general.discussion)
  • Re: count colors in bitmap
    ... But on my own two machines your code DOES crash on a 1024 x 768 bitmap! ... And it also DOES crashes on a 3200 x 2400 pixel bitmap. ... Private Declare Function LoadImage Lib "user32" Alias _ ...
    (microsoft.public.vb.general.discussion)
  • Re: VB3 is making my head spin!
    ... > and displaying it pixel by pixel] tell me how. ... compressed bitmap from an original 24 but full colour bitmap that is held on disk as a standard ... It shows you how to load a full colour 24bit .bmp file from disk and count ... Dim z As Long, t1 As Long, t2 As Long ...
    (comp.lang.basic.visual.misc)