MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Need help about how to bring image to clipboard?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16974] Re: Need help about how to bring image to clipboard?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 10 Apr 1999 02:13:22 -0400
  • Organization: Universitaet Leipzig
  • References: <7ehmf7$o3i@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Ruangyuth,

what you ar doing is a bit long winded. You missuse
the clipboard to get a bitmap repesentation of the
PostScript image. But with DisplayString[]  you can
already create a bitmap from a graphics and to
send the bitmap image via MathLink to your external
program. You can look at the source code of my PNGBitmap
package, it redefines Display[gr,"PNG"] so that a native png-bitmap
can be saved. It calls

DisplayString[graph,"PBM"]

and send the string to the MathLink program. 
The PBM format is quit simple the header consist only of 

P6
width heigth bitdepth
rrgrgbrgb...


when your program has found the width and the height it can
skip to the rgb data in the rest of the string.

In your C-program read the string and convert it from unicode

/* the result of DisplayString[] is get manual */

   MLGetString(stdlink,(const char **) &uni_str);
   len=strlen(uni_str);
   end_str=uni_str+len;
   image_data=pbm=(char *)calloc(len,sizeof(char));
   for(j=i=0,sp=uni_str; i<len; i++) {
     pbm[j++]= (char) MLNextCharacter((const char **)&sp,(const char
*)end_str);
     if(!pbm) break;
    }
   MLDisownString(stdlink,uni_str);

/* now we have C-string and we skip over the header */

  while(*pbm!='\012') pbm++; /* skip over "P6\n" */
  sscanf(++pbm,"%d %d\n",&width,&height);
  while(*pbm!='\012') pbm++;
  sscanf(++pbm,"%d",&bit_depth);
  true_bit_depth=bit_depth=8/*log((double)(bit_depth+1))/M_LN2*/;
  while(*pbm!='\012') pbm++;
  pbm++;
/* ... write the png file */

Here pbm now points to the begin of the rgb-data and of the
pixels.

The Matheamtica code is simple

Display[file_String,gr_,"PNG"]:=
  (PNGBitmap`RawWritePNGGraphics[file,1.0,DisplayString[gr,"PBM"]];gr)

So no clipboard and no keys needed.


Hope that helps

  Jens   

Ruangyuth Inorn wrote:
> 
> Hello all
> 
>  My problem is I must do this series of job
>  - PLot[....]
>  - use mouse right click at the image to copy image to clipboard
>  - call my mathlink program to read DIB image from clipboard to process
>  - Plot[...]
>  - use mouse right click at the image to copy image to clipboard
>  - call my mathlink program to read DIB image from clipboard to process
>   .
>   .
>   .
>   .
> 
>  I must do it for many time and I want to write it to package for do
> this routine job,
> then I want to write this job to package but I didn't know how to bring
> image to
> clipboard without use mouse click, Is someone had any solution? and Is
> Mathematica
> had command to put image direct to clipboard?
> 
> Best Regards
> Ruangyuth Inorn.


  • Prev by Date: Re: New position: MathLink Developer
  • Next by Date: Re: How to interrupt a running evaluation in MathLink
  • Previous by thread: RE: Need help about how to bring image to clipboard?
  • Next by thread: Transformation rules for Floor/Ceiling