Getting Dyalog to handle .jpg and .tiff image files

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
Post Reply
michaelk
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Getting Dyalog to handle .jpg and .tiff image files

Post by michaelk »

Although the Dyalog Image object handles bitmap (.bmp) files, Dyalog does not seem to have a facility to handle other frequently used image formats such as .jpg and .tiff which store images in a more compressed way than .bmp. I am wanting to use Dyalog to place both text and imagery on a page that will be printed. Does anyone have experience in using Dyalog to do this using .jpg or .tiff files, rather than .bmp?
User avatar
Dick Bowman
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm
Contact:

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by Dick Bowman »

Time for a bit of searching, I think.

There was some discussion of this a while back - the short answer being "use .NET". Whether you like that answer being a whole other topic...
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by Morten|Dyalog »

Note that recent versions of Dyalog APL allow you to embed .NET controls within an existing Dyalog form - you do NOT need to rewrite your application using System.Windows.Forms or WPF to take advantage of .NET features. For example:

Code: Select all

      ∇ ShowJPG;win;⎕USING;picbox;f1
[1]   ⍝ Show how to display a JPG in a Dyalog Form using an embedded .NET picturebox
[2]
[3]    ⎕USING←',system.drawing.dll' ',System.Windows.Forms.dll'
[4]
[5]    f1←⎕NEW'Form'(('Caption' 'JPG Display')('Coord' 'Pixel'))
[6]    picbox←f1.⎕NEW'NetControl'(('ClassName' 'System.Windows.Forms.PictureBox')('Posn'(0 0)))
[7]    picbox.Image←⎕NEW System.Drawing.Bitmap(⊂'c:\docs\dyalog\logo\dyalogicon.jpg')
[8]    f1.Size←picbox.Size←picbox.Image.Size.(Height Width)
[9]    ⎕DQ'f1'
     ∇


jpgform.png
jpgform.png (32.47 KiB) Viewed 34482 times

According to http://msdn.microsoft.com/en-us/library/at62haz6.aspx, the list of supported file types is BMP, GIF, EXIF, JPG, PNG and TIFF.

Note that the Bitmap class has a number of interesting properties and methods, like GetThumbnailImage and RotateFlip.

Code: Select all

      picbox.Image.⎕nl -2
 Flags  FrameDimensionsList  Height  HorizontalResolution  Palette  PhysicalDimension  PixelFormat
      PropertyIdList  PropertyItems  RawFormat  Size  Tag  VerticalResolution  Width
      picbox.Image.⎕nl -3
 Clone  CreateObjRef  Dispose  Equals  FromFile  FromHbitmap  FromHicon  FromResource  FromStream
      GetBounds  GetEncoderParameterList  GetFrameCount  GetHashCode  GetHbitmap  GetHicon
      GetLifetimeService  GetPixel  GetPixelFormatSize  GetPropertyItem  GetThumbnailImage  GetType
      InitializeLifetimeService  IsAlphaPixelFormat  IsCanonicalPixelFormat  IsExtendedPixelFormat
      LockBits  MakeTransparent  ReferenceEquals  RemovePropertyItem  RotateFlip  Save  SaveAdd 
      SelectActiveFrame  SetPixel  SetPropertyItem  SetResolution  ToString  UnlockBits
michaelk
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by michaelk »

Morten has shown how to put .jpg imagery into a Windows form. However, I am wanting to put .jpg imagery in a printer object that I have created using the []WC command. In this object I have put text in specified fonts at specified page positions. I want to intermix this text with .jpg images at specified sizes and page positions under program control. Can this be done now in Dyalog? If so, how?

I know that Dyalog can but .bmp images into a printer object, but I'd like to be able to do this also with .jpg and .tiff imagery.
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by Morten|Dyalog »

Well, it CAN be done by extracting the RGB values from the .NET bitmap object created in my example:

Code: Select all

       pixels←bm.GetPixel¨(⍳bm.Size.(Width Height))-⎕IO
       rgb←pixels.(R G B)

It is rather slow at the moment, but speeding up this kind of repeated references of .NET members is something that we have our sights on for a future version.
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by Phil Last »

Morten|Dyalog wrote:

Code: Select all

       pixels←bm.GetPixel¨(⍳bm.Size.(Width Height))-⎕IO
       rgb←pixels.(R G B)

It is rather slow at the moment, ....


Might
      pixels←bm.(GetPixel¨)...
be quicker, parenthesising the derived function within its owner, as it is with references to ordinary namespaces holding APL code?
User avatar
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by Morten|Dyalog »

Only marginally... On my laptop:

3404ms to do: Image.GetPixel¨⍳Image.Size.(Width Height)-⎕IO
3395ms to do: Image.(GetPixel¨⍳Size.(Width Height)-⎕IO)

44550 = Image.Size.(Width×Height)

~13 calls per millisecond.
neeraj
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by neeraj »

Another solution would be to use a third party component. http://www.leadtools.com
neeraj
Posts: 82
Joined: Wed Dec 02, 2009 12:10 am
Location: Ithaca, NY, USA

Re: Getting Dyalog to handle .jpg and .tiff image files

Post by neeraj »

Another solution would be to use a third party component. http://www.leadtools.com
Post Reply