Getting Dyalog to handle .jpg and .tiff image files
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 !
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
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?
- Dick Bowman
- Posts: 235
- Joined: Thu Jun 18, 2009 4:55 pm
- Contact:
Re: Getting Dyalog to handle .jpg and .tiff image files
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...
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
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Getting Dyalog to handle .jpg and .tiff image files
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:
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
∇ 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'
∇
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
Re: Getting Dyalog to handle .jpg and .tiff image files
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.
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.
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Getting Dyalog to handle .jpg and .tiff image files
Well, it CAN be done by extracting the RGB values from the .NET bitmap object created in my example:
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.
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.
Re: Getting Dyalog to handle .jpg and .tiff image files
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?
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Getting Dyalog to handle .jpg and .tiff image files
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.
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.
Re: Getting Dyalog to handle .jpg and .tiff image files
Another solution would be to use a third party component. http://www.leadtools.com
Re: Getting Dyalog to handle .jpg and .tiff image files
Another solution would be to use a third party component. http://www.leadtools.com