trichview.com

trichview.support




SetPictureInfo


Return to index


Author

Message

Stefan Westner

Posted: 01/30/2003 21:22:45


Hello,


I want to resize all picture in a RVF-document to a widht of 300 and convert

it to JPEG.

To do this I iterate through all items and execute the attached code (I use

ImageEn to do my image-related work) (comments are in the code):


        if (rv.GetItemStyle(i)=rvsPicture)

          or (rv.GetItemStyle(i)=rvsHotPicture) then begin

// If it is a picture get the data exspecially the TGraphic

          rv.GetPictureInfo(i, pName, pGr, pAlign, pTag);

// If the picture is no JPEG or more the 300 pixel widht then recalculate

          if not (pGr is TJPEGImage) or (pGr.Width>300) then begin

// Do some inits for ImageEn

            fImageEnIO := TImageEnIO.Create(nil);

            fImageEnProc := TImageEnProc.Create(nil);

            fBitmap := TBitmap.Create;

            fImageEnIO.AttachedBitmap := fBitmap;

            fImageEnProc.AttachedBitmap := fBitmap;

            ms:=TMemoryStream.Create;

            try


              DefGIF_LZWDECOMPFUNC:=GIFLZWDecompress;

              DefGIF_LZWCOMPFUNC:=GIFLZWCompress;

              DefTIFF_LZWDECOMPFUNC:=TIFFLZWDecompress;

              DefTIFF_LZWCOMPFUNC:=TIFFLZWCompress;


              if pGr is TMetaFile then begin

// If it's a metafile load it into ImageEn and resize it to a width of 300

                (pGr as TMetafile).Enhanced:=True;

                (pGr as TMetafile).SaveToFile('D:\test.emf');

                fImageEnIO.ImportMetafile('D:\test.emf', pGr.Width, -1);

                if fImageEnIO.Params.Width>300 then

                  fImageEnProc.Resample(300, -1, rfTriangle);

                DeleteFile('D:\test.emf');

              end

              else begin

// If It's no metafile we could process it directly

                pGr.SaveToStream(ms);

                ms.Position:=0;

                fImageEnIO.LoadFromStream(ms);

                if fImageEnIO.Params.Width>300 then

                  fImageEnProc.Resample(300, -1, rfTriangle);

              end;


              ms.Clear;

// Recalculate the picture and save it as JPEG to the stream

              fImageEnIO.Params.DpiX:=72;

              fImageEnIO.Params.DpiY:=72;

              fImageEnIO.Params.JPEG_Quality:=25;

              fImageEnIO.SaveToStreamJpeg(ms);

              ms.Position:=0;


              pGr:=TJPEGImage.Create;

              (pGr as TJPEGImage).LoadFromStream(ms);

// At this point pGr.Width is 300 and I write it back

              if rv.SetPictureInfo(i, pName, pGr, pAlign, pTag) then

                rv.Format;

            finally

              fImageEnIO.Free;

              fImageEnProc.Free;

              fBitmap.Free;

              ms.Free;

            end;

          end;

        end;


Problem is that the picture is not shown with a width of 300 but with the

width it has before resizing. It seems that TRichview doesn't know the the

pGr width changed. Even the rv.Format doesn't help.


What could I do?


Thanks


Stefan Westner





Powered by ABC Amber Outlook Express Converter