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 !

Getting Dyalog to handle .jpg and .tiff image files

Postby michaelk on Sun Jul 17, 2011 2:48 am

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?
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

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

Postby Dick Bowman on Mon Jul 18, 2011 10:21 am

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
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

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

Postby Morten|Dyalog on Thu Sep 01, 2011 11:41 am

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 29172 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
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

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

Postby michaelk on Sun Sep 04, 2011 12:56 am

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.
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

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

Postby Morten|Dyalog on Sun Sep 04, 2011 8:08 am

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
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

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

Postby Phil Last on Sun Sep 04, 2011 9:12 am

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
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

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

Postby Morten|Dyalog on Mon Sep 05, 2011 10:09 am

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.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

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

Postby neeraj on Sat Sep 10, 2011 5:47 am

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

Postby neeraj on Sat Sep 10, 2011 5:48 am

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


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest