Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

How to display a 24Bit RGB Image ??

64 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Ingo de Boer

ungelesen,
29.11.2000, 03:00:0029.11.00
an

I have a pointer to 24Bit RGB Image from my C/C++ code. I know
how to handle Tcl and C/C++... but...
How do I display the Image in Tcl ?? Is there a sample code
available ??

thanks
Ingo

--
Ingo de Boer
email: i...@ibt.etec.uni-karlsruhe.de

Chengye Mao

ungelesen,
29.11.2000, 03:00:0029.11.00
an
In article <3A24F80E...@ibt.etec.uni-karlsruhe.de>,

It involves three basic steps to put your RGB image data:

1) using either scripts or Tcl_Eval(scripts) in C code to create a Tk
Photo;

2) using Tk_FindPhoto to retrieve the handle of the photo image in your
C code;

3) using Tk_PhotoPutBlock to put your RGB data into the photo in your C
code.

You can use Tcl scripts to display the image in a widget, e.g.,

pack [Label .lable -image photoImageName -anchor nw]

--
Chengye Mao
http://www.geocities.com/~chengye


Sent via Deja.com http://www.deja.com/
Before you buy.

George A. Howlett

ungelesen,
29.11.2000, 03:00:0029.11.00
an
Ingo de Boer <i...@ibt.etec.uni-karlsruhe.de> wrote:

> I have a pointer to 24Bit RGB Image from my C/C++ code. I know
> how to handle Tcl and C/C++... but...
> How do I display the Image in Tcl ?? Is there a sample code
> available ??

First, create an empty Tk photo image.

set img [image create photo]

Then give the name of it and your RGB image to your C++ routine.

fill $img

The photo will then automatically contain your image. You can
then display it like any Tk photo.

label .l -image $img
pack .l

Here's some sample code. It assumes that the image data and size are
already available and stored in some global variables.

int imageWidth, imageHeight;
unsigned char imageData[];

int
FillCmd(
ClientData clientData,
Tcl_Interp *interp,
int argc,
char **argv)
{
Tk_PhotoImageBlock dest;
Tk_PhotoHandle photo;

if (argc != 2) {
Tcl_AppendResult(interp,
"wrong #args: should be \"", argv[0], " photoName\"", (char *)NULL);
return TCL_ERROR;
}
photo = Blt_FindPhoto(interp, argv[1]);
if (photo == NULL) {
Tcl_AppendResult(interp, "photo \"", argv[1], "\" doesn't",
" exist or is not a photo image", (char *)NULL);
return TCL_ERROR;
}

Tk_PhotoGetImage(photo, &dest);
dest.pixelSize = 4;
dest.pitch = dest.pixelSize * imageWidth;
dest.width = imageWidth;
dest.height = imageHeight;
dest.offset[0] = 0;
dest.offset[1] = 1;
dest.offset[2] = 2;
dest.offset[3] = 0; /* Don't use the alpha channel for
* transparency. */
dest.pixelPtr = (char *)imageData;
Tk_PhotoSetSize(photo, imageWidth, imageHeight);
Tk_PhotoPutBlock(photo, &dest, 0, 0, imageWidth, imageHeight);
return TCL_OK;
}

This assumes your data is store 4 bytes per pixel. If it's 3,
then change the pixel size.

dest.pixelSize = 3;

Hope this helps.

--gah

0 neue Nachrichten