MBS Plugins and .ico creation?

  1. ‹ Older
  2. 4 years ago

    Christian S

    4 Jun 2015 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    Icons for Mac or Win?

    Because I think the plugin does only Mac icons there.

    But GraphicsMagick plugin could be able to write ico file.

  3. My OS X app already creates .icns files for OS X, but I now need to create .ico files for Windows.
    I have looked in the GraphicsMagick examples folder, but can see no example there?

    Thanks.

  4. Joe R

    4 Jun 2015 Xojo Inc

    @Richard S My OS X app already creates .icns files for OS X, but I now need to create .ico files for Windows.

    What platform is the app creating the ico files running on?

  5. OS X

  6. Michel B

    4 Jun 2015 Pre-Release Testers RubberViews.com

    @ChristianSchmitz GraphicsMagick plugin could be able to write ico file.

    Imagemagick indeed lists ico as one of the formats it supports :
    http://www.imagemagick.org/script/formats.php

  7. Edited 4 years ago

    Michel,
    according to that link it can only READ .ico, not write?

    So basically, am I correct in thinking that MBS plugins cannot create .ico files, and an additional plugin is required?
    Will definitely forget that idea then.

    Thank you all so much for trying to help.

  8. Michel B

    4 Jun 2015 Pre-Release Testers RubberViews.com

    @Richard S according to that link it can only READ .ico, not write?

    You are right. I read too fast. Sorry.

  9. Joe R

    4 Jun 2015 Xojo Inc

    @Richard S OS X

    This can be done without plugins on OS X. Try using Picture.GetData("com.microsoft.ico").

  10. Edited 4 years ago

    Joe - is that pure Xojo code, and if so - what part of the Language Reference should I look at?
    I cannot work out what the com.microsoft.ico part of the code refers to?

    Thaks.

  11. Michel B

    4 Jun 2015 Pre-Release Testers RubberViews.com
    Edited 4 years ago

    @Joe R This can be done without plugins on OS X. Try using Picture.GetData("com.microsoft.ico").

    Joe, this is intriguing. There is no mention of that in the LR at http://docs.xojo.com/index.php/Picture.GetData

    And it does not seem like FromData would create an ico back, right ?

  12. Joe R

    4 Jun 2015 Xojo Inc

    @Richard S Joe - is that pure Xojo code, and if so - what part of the Language Reference should I look at?
    I cannot work out what the com.microsoft.ico part of the code refers to?

    Thaks.

    It's a uniform type identifier, which can be passed to FromData on OS X. Passing it on other platforms won't work.

  13. Joe R

    4 Jun 2015 Xojo Inc

    @Michel B And it does not seem like FromData would create an ico back, right ?

    I think FromData on OS X can parse an ico file, but it definitely won't retain the multiple representations that are inside of it.

  14. Edited 4 years ago

    Ok, I seem to be missing something here?

    The code Joe posted looks like it reads an image file, and puts it into a memory block.
    Am I correct in thinking that I then need to use FromData, to output this memory block data as a .ico file?

    If so, I can see no info in the LR which explains how to output as a .ico? it simply shows how to load it into an image well.

    I have also just noticed that Joe said it would not retain any other representations included - which really makes the entire exercise completely pointless :(

    Thanks anyway.

  15. Joe R

    4 Jun 2015 Xojo Inc

    @Richard S I have also just noticed that Joe said it would not retain any other representations included - which really makes the entire exercise completely pointless :(

    Yeah, that's a fair point. I hadn't thought of that initially when I posted.

  16. Christian S

    4 Jun 2015 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    I'm sorry. GraphicsMagick does not do ICO file writing.

    And so far I only did it on Windows via API functions.
    But you can of course just code yourself a function to write those files.
    The format should not be too hard.

  17. Sam R

    4 Jun 2015 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    CGImageDestination can create .ico files, but it doesn't create any of the newer resolutions.

    last time I looked at the .ico format, they were just a string of Windows bitmap images.

  18. Joe R

    4 Jun 2015 Xojo Inc
    Edited 4 years ago

    @Sam R last time I looked at the .ico format, they were just a string of Windows bitmap images.

    Slightly more complicated than that, but not too bad. There's some documentation on the ICO Wikipedia page , which seems like it contains all of the information you need. If you're targeting Vista and later, you only have to worry about putting PNGs in the ICO.

    For fun, here's some history of the format:

  19. Michel B

    4 Jun 2015 Pre-Release Testers RubberViews.com
    Edited 4 years ago

    @Joe R Slightly more complicated than that, but not too bad. There's some documentation on the ICO Wikipedia page , which seems like it contains all of the information you need. If you're targeting Vista and later, you only have to worry about putting PNGs in the ICO.

    Norman created an iCO exporter for Richard from the Wikipedia page back in October 2014 :
    https://forum.xojo.com/16314-create-a-ico-file?search=%22ico+exporter%22

  20. Wow - I don't even remember ever seeing that post!
    Will take a look at that now :)

    Thanks for pointing that out Michel :)

  21. last week

    Michael D

    Jan 7 Pre-Release Testers, Xojo Pro

    I ran into some issues using Norman's algorithm, and found 3 small changes made it work:

    • set the # of color planes to 1 (rather than 0)
    • set the bits per pixel to 32 (rather than 0)
    • set the BinaryStream to littleEndian.

    Revised code here:

    Public Function MakeICOfromPicture(p as Picture) as MemoryBlock
      ' adatpted from https://forum.xojo.com/16314-create-a-ico-file?search=%22ico+exporter%22
      ' see also https://en.wikipedia.org/wiki/Favicon
      
      ' for standard web favicon.ico one should use 16x16, 32x32 and 48x48 (and possibly 64x64 says wikipedia)
      
      
      if p = nil then 
            return nil
      end if
      
      'ICONDIR structure
      'Offset#    Size (in bytes)    Purpose
      '0    2    Reserved. Must always be 0.
      '2    2    Specifies image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid.
      '4    2    Specifies number of images in the file.
      'Structure of image directory
      '
      'Image #1    Entry for the first image
      'Image #2    Entry for the second image
      '...
      'Image #n    Entry for the last image
      '
      '
      'Image entry
      'ICONDIRENTRY structure
      'Offset#    Size (in bytes)    Purpose
      '0    1    Specifies image width in pixels. Can be any number between 0 and 255. Value 0 means image width is 256 pixels.
      '1    1    Specifies image height in pixels. Can be any number between 0 and 255. Value 0 means image height is 256 pixels.
      '2    1    Specifies number of colors in the color palette. Should be 0 if the image does not use a color palette.
      '3    1    Reserved. Should be 0.[Notes 2]
      '4    2    In ICO format: Specifies color planes. Should be 0 or 1.[Notes 3]
      'In CUR format: Specifies the horizontal coordinates of the hotspot in number of pixels from the left.
      '
      '6    2    In ICO format: Specifies bits per pixel. [Notes 4]
      'In CUR format: Specifies the vertical coordinates of the hotspot in number of pixels from the top.
      '
      '8    4    Specifies the size of the image's data in bytes
      '12    4    Specifies the offset of BMP or PNG data from the beginning of the ICO/CUR file
      
      
      
      ' downsize master picture to each smaller size
      
      dim sizes() as integer= array(16,32,48,64)
      dim images() as Picture
      dim patchAddresses() as int32
      
      // downsize to needed sizes
      for each size as integer  in sizes
          dim p2 as new Picture(size,size)
          p2.graphics.drawPicture(p,0,0,p2.width,p2.height,0,0,p.width,p.height)
          images.append p2
       next
     
       
      ' write the header
      
      Dim mb as New MemoryBlock(0)
      Dim bs as New BinaryStream(mb)
      bs.LittleEndian = true
      
      dim offset as integer
      
      bs.WriteInt16 0 '    Reserved. Must always be 0.
      offset = offset + 2
      
      bs.WriteInt16 1 ' Specifies image type: 1 for icon (.ICO)
      offset = offset + 2
      
      bs.WriteInt16 ubound(images)+1 ' Specifies number of images in the file.
      offset = offset + 2
      
      
      ' write the catalog
      for each img as PIcture in images
        bs.WriteInt8 img.Width
        offset = offset + 1
        
        bs.WriteInt8 img.Height
        offset = offset + 1
        
        bs.WriteInt8 0   ' # of colors in color palette (0)
        offset = offset + 1
        
        bs.WriteInt8 0   ' reserved must always be zero
        offset = offset + 1
        
        //bs.WriteInt16 0  '  # of color planes
        bs.WriteInt16 1  '  # of color planes  (1 seems more standard)
        offset = offset + 2
        
        bs.WriteInt16 32 ' bits per pixel (supposedly can be zero, since we are using PNG, but 32 seems required)
        offset = offset + 2
        
        dim tmpmb as memoryblock = img.GetData( picture.FormatPNG )
        bs.WriteInt32 tmpmb.Size
        offset = offset + 4
        bs.WriteInt32 0
        // hang on to this position as we need to back patch it as we spit out images
        patchAddresses.append offset
        offset = offset + 4
      next
      
      dim i as integer
      for each img as picture in images
        mb.Int32Value(patchAddresses(i)) = offset
        i = i + 1
        dim tmpmb as memoryblock = img.GetData( picture.FormatPNG )
        bs.Write tmpmb.StringValue(0, tmpmb.Size)
        offset = offset + tmpmb.Size
      next
      
      bs.Close
      
      return mb 
    End Function

or Sign Up to reply!