Board index » cppbuilder » hope this is not a silly question but...

hope this is not a silly question but...


2004-08-03 04:23:51 PM
cppbuilder33
Maybe its just me, but i cant seem to understand exactly how to use
the timage component to embed bitmaps, or tiffs or jpegs into my
program.
I wanted to have a application that i can distribute as an independant
exe, and i wanted to embed several 1024x768 and 1280x1024 images in
the application exe, so that they would not have to be loaded as
seperate files
I would be looking to embed a total of 10 images (5 at each
resolution)
Once they are embeded i may need to proccess these images on a pixel
by pixel basis, but i know doing so will be slow. I find the scanline
function confusing, it seems to access line by line, i know thats
faster but how does it let me access the pixel data ?
Any help appreciated
thanks
 
 

Re:hope this is not a silly question but...

Peted wrote:
Quote
[...] i cant seem to understand exactly how to use the
timage component to embed bitmaps, or tiffs or jpegs into my
program.
Don't. Put them into a resource file instead that will get
compiled into the exe.
The resourse editor that comes with BCB only supports 16 color
bitmaps but you can use it to play with a .res file to see how it works. Several other editors that support 256 colors can be
found for free and downloaded.
As for the image type, I would stay with a bitmap because it's
higher quality and I would store only 1 copy of each at the
lower resolution. There are functions to stretch the bitmap
(if needed) to different resolutions. You might even find that
a bitmap at an even lower resolution works just as well.
Quote
Once they are embeded i may need to proccess these images on a pixel
by pixel basis, but i know doing so will be slow.
Not too bad if you use an off-screen or in-memory bitmap
and copy it (or portions of it) to the on-screen bitmap.
Quote
I find the scanline function confusing,
Take a look at the TBitmap object. You can get at pixels easily:
Bitmap1->Canvas->Pixels[ x ][ y ] = some color;
~ JD
 

Re:hope this is not a silly question but...

"JD" < XXXX@XXXXX.COM >wrote in message
Quote

Peted wrote:
>[...] i cant seem to understand exactly how to use the
>timage component to embed bitmaps, or tiffs or jpegs into my
>program.

Don't. Put them into a resource file instead that will get
compiled into the exe.

The resourse editor that comes with BCB only supports 16 color
bitmaps but you can use it to play with a .res file to see how it works.
Several other editors that support 256 colors can be
found for free and downloaded.

erm..I've been trying to use the resource file to store my bitmaps of the
application I'm working on, but have encountered 3 problems:
1) When I try to cut and paste the picture into the resource bitmap (Image
Editor do not allow importing Bitmaps directly...)(the original bitmap is a
100x100 24 bit bitmap, later scaled down to 256 colours using Windows System
Palette, as stated by Photoshop), the Image Editor told me that resource
file only supports 256 colour image. Fine, I can live with the ugly
dithering artifect of converting a 24 bit graphics to 256 colour, but I
really wish my application can show the bitmaps in their full glory....
2) When I paste the image into the resource bitmap (using Image Editor
included with BCB6), the graphic will not use it's original palette, but
using the ugly default palette of Image Editor. The bitmap became dull and
dark... There is no way to edit the palette of I.E. and I don't think I will
want to edit all 256 entries just to get my image look right. So, is there
anyway I could import Bitmaps with more than 256 colours into a resource
file? Also, is there any other tools I can use to handle a resource file
other than that inferior Image Editor?
3) everytime I changed any of the bitmaps I included to the resoucr file
(edit, remove or add new bitmaps), it will not be refreshed in my program,
even when I remake and rebuild my application. I have to remove the .res
file and re-add it to my project, is this a bug?
Okay, I know I shouldn't be jacking others thread, but I really got simillar
problems with others...
Currently, I use TImageList to solve my problem, but I really like to know
more about how to manipulate the resource file.
Regards.
 

{smallsort}

Re:hope this is not a silly question but...

So is the idea, then save the bitmap (256 colours is fine for me) as a
res file, add it to the project, but then what ?
Once its added to the project, can i assign it to a Timage component
and access the bitmap data that way ??
any advice appreciated
thanks
Quote
>[...] i cant seem to understand exactly how to use the
>timage component to embed bitmaps, or tiffs or jpegs into my
>program.

Don't. Put them into a resource file instead that will get
compiled into the exe.

The resourse editor that comes with BCB only supports 16 color
bitmaps but you can use it to play with a .res file to see how it works. Several other editors that support 256 colors can be
found for free and downloaded.

As for the image type, I would stay with a bitmap because it's
higher quality and I would store only 1 copy of each at the
lower resolution. There are functions to stretch the bitmap
(if needed) to different resolutions. You might even find that
a bitmap at an even lower resolution works just as well.

>Once they are embeded i may need to proccess these images on a pixel
>by pixel basis, but i know doing so will be slow.

Not too bad if you use an off-screen or in-memory bitmap
and copy it (or portions of it) to the on-screen bitmap.

>I find the scanline function confusing,

Take a look at the TBitmap object. You can get at pixels easily:

Bitmap1->Canvas->Pixels[ x ][ y ] = some color;

~ JD
 

Re:hope this is not a silly question but...

On Wed, 04 Aug 2004 15:07:54 +0800, <Peted>wrote:
Quote

So is the idea, then save the bitmap (256 colours is fine for me) as a
res file, add it to the project, but then what ?

Once its added to the project, can i assign it to a Timage component
and access the bitmap data that way ??


any advice appreciated


thanks


Yes,
Just use a TResourceStream and the TBitmap LoadFromStream method.
Simon
 

Re:hope this is not a silly question but...

On Wed, 4 Aug 2004 13:44:15 +0800, newsreader < XXXX@XXXXX.COM >
wrote:
Quote


erm..I've been trying to use the resource file to store my bitmaps of the
application I'm working on, but have encountered 3 problems:

<snip>lots of problems</snip>
we get around all this by putting the images into an rc file, this then
gets compiled by the resource compiler into a res file that is added to
the exe. You can then get the images out the exact same way as you do
currently, but you don't have the sucky 256 colour limit. Also, if you
change the source image, it is automatically changed in the exe.
Otherwise, investigate a thirdparty resource editor that will allow you to
have more than 256 colours.
Simon
 

Re:hope this is not a silly question but...

Peted wrote:
Quote

So is the idea, then save the bitmap (256 colours is fine for me) as a
res file, add it to the project, but then what ?
To be clear, you save the bitmap as a bitmap. You need another
program that can add the bitmap to a .res file.
You have 2 types of programs that you can use to get the
bitmap into a .res file. One is a resource editor and the
other is a resource compiler. BCB comes with both. However,
the editor (click Tools | Image Editor) does not support 256
colors so you need to use the resource compiler or some other
editor.
Your program can have one or many .res files. I would
reccommend that you not use the default .res thats generated
by the IDE because the IDE takes a snapshot of it and
frequently rebuilds it - resulting in loss of all your work
unless you delete this and that before you do this and that so
that the snapshot includes your additions. I did it once but
don't recall the exact steps.
This link details all of the steps to create a .res file using the resourse compiler.
www.bcbdev.com/faqs/faq52.htm
In general:
Create a text file with the extension of .rc which
is the source file for the compiler.
Create a text file with the same name as the .rc file but
with the extention of .rh which is the header file to the
source.
Pass the .rc file to the compiler.
Make sure the new .res file is in the same folder as the
target application.
That's all there is to making a .res file (for only a bitmap).
Then to use it, optionally include the .rh so you don't have
duplicate code and get the resource added to a particular unit.
Note that if you add it to more than one form, it does not take
more memory.
#include "MyResource.rh"
#pragma resource "MyResource.res"
There's a bunch of ways to grab a bitmap from a .res file. The
easiest way is to use the built-in method of a TBitmap, of
which there are 2 to pick from. One loads using a string to
identify the bitmap and the other uses a numeric ID. The
reason that there are 2 methods is that it depends on how
the .res was created. If created with an editor, you must use
the string method. Since you're using the compiler, you want
to use the ID method:
Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->LoadFromResourceID( (int)HInstance, ID_BITMAP1 );
where ID_BITMAP1 is a #define in your .rh file.
~ JD
Please trim your posts.
 

Re:hope this is not a silly question but...

"Simon Macneall" <macneall@iinet-dot-net-dot-au>wrote:
Quote
[...] Also, if you change the source image, it is
automatically changed in the exe.
IS IT REALLY?? I have to wonder why this is the first that I've
heard of it. That could be quite handy you know. Good tip.
~ JD
 

Re:hope this is not a silly question but...

As Simon pointed out, you want to use a resource compiler
instead of an editor. BCB has one, MS has one and there are
others as well. They all produce the same result.
Here's a link to how to create and use a .res file with a
compiler:
www.bcbdev.com/faqs/faq52.htm
You might also want to look at my reply to Peted in this
thread.
~ JD
 

Re:hope this is not a silly question but...

On 4 Aug 2004 01:40:13 -0700, JD < XXXX@XXXXX.COM >wrote:
Quote

"Simon Macneall" <macneall@iinet-dot-net-dot-au>wrote:
>[...] Also, if you change the source image, it is
>automatically changed in the exe.

IS IT REALLY?? I have to wonder why this is the first that I've
heard of it. That could be quite handy you know. Good tip.

I may have misled you slightly, not sure if a make will automatically
notice that the rc file needs recompiling, but a build certainly will. We
use command line where we explicitly tell the compiler about the image
dependencies.
Simon
 

Re:hope this is not a silly question but...

Big thanks to Simon, I took your advice and managed to include the images
into my project without having have to sacrifice the image quality. However,
I would like to ask one more question:
Is there any free resource editor (the one that can create a .rc file)
available? I searched around and only found some resource compiler that only
support opening a .res file and at the best, recompile it. I ended up having
have to install a trial version of Visual C++ to do the job, but I don't
feel comfortable with this solution as there is a time limit. Or if the
creation of a resource script is so trivial that we do not need a dedicated
editor, is there any guides or tutorials about how to create a resource
script? (I know about opening a text file with note pad, what I want to know
is the rules and format of a resource script)
Regards.
"Simon Macneall" <macneall@iinet-dot-net-dot-au>wrote in message
Quote
On 4 Aug 2004 01:40:13 -0700, JD < XXXX@XXXXX.COM >wrote:

>
>"Simon Macneall" <macneall@iinet-dot-net-dot-au>wrote:
>>[...] Also, if you change the source image, it is
>>automatically changed in the exe.
>
>IS IT REALLY?? I have to wonder why this is the first that I've
>heard of it. That could be quite handy you know. Good tip.
>
I may have misled you slightly, not sure if a make will automatically
notice that the rc file needs recompiling, but a build certainly will. We
use command line where we explicitly tell the compiler about the image
dependencies.

Simon
 

Re:hope this is not a silly question but...

On Thu, 5 Aug 2004 14:15:19 +0800, newsreader < XXXX@XXXXX.COM >
wrote:
Quote
Big thanks to Simon, I took your advice and managed to include the images
into my project without having have to sacrifice the image quality.
However,
I would like to ask one more question:

Is there any free resource editor (the one that can create a .rc file)
available?
We just manually edit the rc file. It is pretty trivial, the hardest part
is setting up the file version info, but once you have one, you can just
copy and paste. Most images just go in as RC_DATA, to be read out later in
your code.
Quote
(I know about opening a text file with note pad, what I want to know
is the rules and format of a resource script)

I don't know of any tutorials, and you don't have to bother with notepad,
just add the .rc file to your borland project and edit it in borland's ide.
Simon
 

Re:hope this is not a silly question but...

"newsreader" < XXXX@XXXXX.COM >wrote:
Quote
[...] is there any guides or tutorials about how to create a
resource script?
If you see my other reply, you'll find *everything* that you
need to know. lso be sure to read my reply to Petre.
~ JD