Newsgroup: it.comp.lang.visual-basic
Titolo: [?] Inserire immagini in RTF

ciao a tutti
osservando cosa scrive Word salvando un RTF, e spulciando alcuni documenti
tecnici, mi sono creato una classe per la scrittura di file in formato RTF.
So riuscito a riprodurre diverse funzionalità di Word fra cui la creazione
di tabelle etc..
Il grosso ostacolo che incontro è quello di poter inserire una immagine BMP
o JPG o altro formato, includendola staticamente, ovvero senza ricorrere a
codici di campo che richiamano il file.
La documentazione sull'Rtf è misera e dice solo poche cose, ho provato ad
includere un bitmap in word e poi salvarlo in RTF per vedere che cavolo ci
scrive dentro...sembrerebbe che prenda il bitmap e lo converta in
esadecimale per poterlo scrivere in modalità testo...il problema è che non
so da dove prende i dati da convertire in esadecimale. Io pensavo di
utilizzare la funzione API GetDIBits che mi ritorna i dati di una bitmap per
poi convertirli in esadecimale, ma niente da fare, non trovo corrispondenza
fra quelli che calcolo io e quelli che inserisce word a parità di immagine
bitmap.
Avete suggerimenti da darmi? ve ne sarei veramente grato
ciao a tutti e grazie

di tabelle etc..
Purtroppo non so la risposta...A me piacerebbe fare lo stesso in C++ &
Win32. Il tuo codice e' disponibile ? Nel caso (quasi ovvio e
legittimo) di risposta negativa hai una lista di siti (oltre al
classico 
http://www.wotsit.org/
) dove recuperare documentazione utile
?
Grazie e ciao
Stefano "HappyMan" (Lago Maggiore - NO)
--
Personal Web 
http://www.sgr.info
Email happyman69 (at) 
libero.it

Ciao,
ecco cosa cercavi, con l'ausilio di una piccola API si risolve il problema:
DICHIARAZIONE API
Private Const WM_PASTE As Long = &H302
Private Declare Function SendMessage Lib "User32.dll" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
CODICE
  'Copia l'immagine negli Appunti di Windows.
  Clipboard.Clear
  Clipboard.SetData Image1.Picture, vbCFBitmap
  'Copia l'immagine nel controllo RichTextBox.
  SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
Ciao, Luciano.

 ha scritto nel messaggio
news:DQBT9.14717$AA2.6...@news2.tin.it...


prova a vedere questo sito per la documentazione rtf
http://impulzus.sch.bme.hu/tom/szamitastechnika/file/rtfspec/rtfspec.htm
il grosso del lavoro io l'ho fatto semplicemente scrivendo in word quello
che mi serviva, ad esempio una tabella o un codice di campo, e guardando
cosa spara fuori salvando in rtf....
Il codice che ho fatto è molto semplice, consiste nello scrivere un header
iniziale (copiato da word logicamente), e poi inserisco le varie stringhe
formattate con i codici rtf (altezza del testo, grassetto, corsivo). Alla
fine scrivo la parte finale dell'rtf (anche questa copiata da Word) per
chiudere l'rtf...Se usi MFC in c++ presumo che ci siano già delle classi per
la gestione RTF. Ogni volta che devo inserire una cosa nuova, la genero in
word e poi salvo l'rtf, vedo quali sono le parti variabile e le cambio
dinamicamente nel mio codice.
Fino ad ora ho trovato la cosa relativamente semplice, a parte questa
faccenda delle immagini che sono riuscito a gestire solo mediante dei codici
di campo, ovvero un link al file fisico su disco che deve sempre seguire il
file rtf nei suoi eventuali spostamenti.

Ho capito cosa intendi, ma io non uso un controllo RTF, ma una classe fatta
da me che mi permette di creare al volo un file rtf

> Mah, io te la butto li', ma non so' se possa funzionare.....
sig! avevo già provato anche questa ma non funziona purtroppo

prova a leggere questo (anche se la formattazione è andata a farsi
benedire)...
Pictures
An RTF file can include pictures created with other applications. These
pictures can be in hexadecimal (the default) or binary format. Pictures are
destinations, and begin with the \pict control word. The \pict keyword is
preceded by \*\shppict destination control keyword as described in the
following example. A picture destination has the following syntax:
<pict>'{' \pict (<brdr>? & <shading>? & <picttype> & <pictsize> &
<metafileinfo>?) <data> '}'
<picttype>| \emfblip | \pngblip | \jpegblip | \macpict | \pmmetafile |
\wmetafile | \dibitmap <bitmapinfo> | \wbitmap <bitmapinfo>
<bitmapinfo>\wbmbitspixel & \wbmplanes & \wbmwidthbytes
<pictsize>(\picw & \pich) \picwgoal? & \pichgoal? \picscalex? & \picscaley?
& \picscaled? & \piccropt? & \piccropb? & \piccropr? & \piccropl?
<metafileinfo>\picbmp & \picbpp
<data>(\bin #BDATA) | #SDATA
These control words are described in the following table. Some measurements
in this table are in twips; a twip is one-twentieth of a point.
Control WordMeaning
\emfblipSource of the picture is an EMF (enhanced metafile).
\pngblipSource of the picture is a PNG.
\jpegblipSource of the picture is a JPEG.
\shppictSpecifies a Word 97 picture. This is a destination control word.
\nonshppictSpecifies that Word 97 has written a {\pict destination that it
will not read on input. This keyword is for compatibility with other
readers.
\macpictSource of the picture is QuickDraw.
\pmmetafileNSource of the picture is an OS/2 metafile. The N argument
identifies the metafile type. The N values are described on page 43 of this
Application Note.
\wmetafileNSource of the picture is a Windows metafile. The N argument
identifies the metafile type (the default is 1).
\dibitmapNSource of the picture is a Windows device-independent bitmap. The
N argument identifies the bitmap type (must equal 0).
The information to be included in RTF from a Windows device-independent
bitmap is the concatenation of the BITMAPINFO structure followed by the
actual pixel data.
\wbitmapNSource of the picture is a Windows device-dependent bitmap. The N
argument identifies the bitmap type (must equal 0).
The information to be included in RTF from a Windows device-dependent bitmap
is the result of the GetBitmapBits function.
Example:
{\*\shppict {\pict \emfblip ... }}{\nonshppict {\pict ..}}
For more information on the GetDIBits and GetBitmapBits functions and the
structure of Windows device-independent and device-dependent bitmaps, see
Volume 1 and Volume 2 of the Programmer's Reference in the Microsoft Windows
3.1 Software Development Kit. For best device-independence and
interoperability with Microsoft products, however, use of the \wbitmap and
\dibitmap control words is discouraged. Rather, bitmaps should be embedded
within Windows metafiles and the \wmetafile control word used. For more
information on embedding bitmaps within metafiles, see Volume 1 and Volume 2
of the Programmer's Reference in the Microsoft Windows 3.1 Software
Development Kit.
Control wordMeaning
Bitmap Information
\wbmbitspixelNNumber of adjacent color bits on each plane needed to define a
pixel (the default is 1).  Possible values are 1 (monochrome), 4 (16
colors), 8 (256 colors) and 24 (RGB).
\wbmplanesNNumber of bitmap color planes (must equal 1).
\wbmwidthbytesNSpecifies the number of bytes in each raster line. This value
must be an even number because the Windows graphics device interface (GDI)
assumes that the bit values of a bitmap form an array of integer (two-byte)
values. In other words, \wbmwidthbytes times 8 must be the next multiple of
16 greater than or equal to the \picw (bitmap width in pixels) value.
Picture Size, Scaling, and Cropping
\picwNxExt field if the picture is a Windows metafile; picture width in
pixels if the picture is a bitmap or from QuickDraw. The N argument is a
long integer.
\pichNyExt field if the picture is a Windows metafile; picture height in
pixels if the picture is a bitmap or from QuickDraw. The N argument is a
long integer.
\picwgoalNDesired width of the picture in twips. The N argument is a long
integer.
\pichgoalNDesired height of the picture in twips. The N argument is a long
integer.
\picscalexNHorizontal scaling value. The N argument is a value representing
a percentage (the default is 100).
\picscaleyNVertical scaling value. The N argument is a value representing a
percentage (the default is 100).
\picscaledScales the picture to fit within the specified frame. Used only
with \macpict pictures.
\picpropIndicates there are shape properties applied to an inline picture.
This is a destination control word.
\piccroptNTop cropping value in twips. A positive value crops toward the
center of the picture; a negative value crops away from the center, adding a
space border around picture (the default is 0).
\piccropbNBottom cropping value in twips. A positive value crops toward the
center of the picture; a negative value crops away from the center, adding a
space border around picture (the default is 0).
\piccroplNLeft cropping value in twips. A positive value crops toward the
center of the picture; a negative value crops away from the center, adding a
space border around picture (the default is 0).
\piccroprNRight cropping value in twips. A positive value crops toward the
center of the picture; a negative value crops away from the center, adding a
space border around picture (the default is 0).
Metafile Information
\picbmpSpecifies whether a metafile contains a bitmap.
\picbppNSpecifies the bits per pixel in a metafile bitmap. The valid range
is 1-32, with 1, 4, 8, and 24 being recognized.
Picture Data
\binNThe picture is in binary format. The numeric parameter N is the number
of bytes that follow. Unlike all other controls, this control word takes a
32-bit parameter.
\blipupiNN represents units per inch on a picture (only certain image types
need or output this)
\blipuid XXXXXUsed as: {\*\blipuid XXXXX} where XXXX is a 16-byte
identification number for the image.
\bliptagNA mostly unique identifier for a picture, where N is a long integer
value.
The \wbitmap control word is optional. If no other picture type is
specified, the picture is assumed to be a Windows bitmap. If \wmetafile is
specified, the N argument can be one of the following types.
TypeN argument
MM_TEXT1
MM_LOMETRIC2
MM_HIMETRIC3
MM_LOENGLISH4
MM_HIENGLISH5
MM_TWIPS6
MM_ISOTROPIC7
MM_ANISOTROPIC8
For more information about these types, see volume 1 of the Programmer's
Reference in the Microsoft Windows 3.1 Software Development Kit.
If \pmmetafile is specified, the N argument can be one of the following
types.
TypeN argument
PU_ARBITRARY0x0004
PU_PELS0x0008
PU_LOMETRIC0x000C
PU_HIMETRIC0x0010
PU_LOENGLISH0x0014
PU_HIENGLISH0x0018
PU_TWIPS0x001C
For more information about these types, see volume 2 of the OS/2 Programmer'
s Reference.
Be careful with spaces following control words when dealing with pictures in
binary format. When reading files, RTF considers the first space after a
control word the delimiter and subsequent spaces part of the document text.
Therefore, any extra spaces are attached to the picture, with unpredictable
results.
RTF writers should not use the carriage-return/linefeed (CR/LF) combination
to break up pictures in binary format. If they do, the CR/LF combination is
treated as literal text and considered part of the picture data.
The picture in hexadecimal or binary format follows the picture-destination
control words. The following example illustrates the destination format:
{\pict\wbitmap0\picw170\pich77\wbmbitspixel1\wbmplanes1\wbmwidthbytes22
\picwgoal505
\pichgoal221
\picscalex172
\picscaley172
49f2000000000273023d1101a030
3901000a000000000273023d98
0048000200000275
02040000200010275023e000000000
273023d000002b90002b90002
b90002b90002b9
0002b90002b90002b90002b90002b90002
b92222b90002b90002b90
002b90002b9
0002b90002b90002b90002b9000