Picture.Open fails for valid FolderItems containing Umlauts (Win/Web)

Dim p As Picture = Picture.Open(f)

will always fail when the FolderItem f has an umlaut in its name. Only on Windows/Web. Windows Desktop works, so does Mac/Web/Desktop. Reported here: <https://xojo.com/issue/41261>

What is the best way to work around that bug? BinaryStream and then Picture.Open(mb)? Unfortunately, I cannot rename the files in every case.

Thanks in advance for your advice :slight_smile:

What if you save f.name in a variable, rename it to a b64 enc of its name, process it how you see fit and when you’re done, rename it back to its original filename again?

Just a wild thought :stuck_out_tongue:
Be aware that i’ve been up since 0500 so my advice might be useless as of now…

Well I can’t rename the file in every case… :frowning: However, the BinaryStream/MemoryBlock option works!

Same for me :wink:

This might be related to Unicode Normalization.

Here it’s code I use for normalization is some cases, but I’m not sure if this can help you.

Function Normalize(extends s as String, form as UInt32) As String
  
  // Normalizes characters of a text string according to Unicode 4.0 TR#15
  
  // can't normalize a string with unknown encoding
  if Encoding(s) is nil then
    return s
  end if
  
  // can't normalize a string not encoded in UTF8
  if Encoding(s) <> Encodings.UTF8 then
    return ConvertEncoding(s, Encodings.UTF8)
  end if
  
  
  #if targetMacOS
    
    soft declare function CFStringCreateMutableCopy lib "Carbon.framework" ( _
    alloc as Ptr, _
    maxLength as UInt32, _
    theString as CFStringRef) as CFStringRef
    
    soft declare sub CFStringNormalize lib "Carbon.framework" (theString as CFStringRef, theForm as UInt32)
    
    dim mutableStringRef as CFStringRef = CFStringCreateMutableCopy(nil, 0, s)
    
    CFStringNormalize mutableStringRef, form
    return mutableStringRef
    
    
    'enum CFStringNormalizationForm {
    'kCFStringNormalizationFormD = 0,
    'kCFStringNormalizationFormKD = 1,
    'kCFStringNormalizationFormC = 2,
    'kCFStringNormalizationFormKC = 3
    
    
  #elseif targetWin32
    
    // not available on Windows < Vista
    if not system.isFunctionAvailable("NormalizeString", "Normaliz.dll") then
      return s
    end if
    
    'soft declare function GetLastError lib "Kernel32.dll" () as UInt32
    
    soft declare function NormalizeString lib "Normaliz.dll" ( _
    NormForm as Int32, _
    lpSrcString as WString, _
    cwSrcLength as integer, _
    lpDstString as Ptr, _
    cwDstLength as integer) as integer
    
    dim estimatedSize as integer = NormalizeString(form, s, len(s), nil, 0)
    
    if estimatedSize > 0 then
      dim m as new memoryBlock(estimatedSize)
      dim newSize as integer = NormalizeString(form, s, lenb(s), m, m.size)
      return ConvertEncoding(DefineEncoding(m.stringValue(0, newSize*2), Encodings.UTF16), Encodings.UTF8)
    else
      return ""
    end if
    
    ' if estimatedSize <= 0 then
    ' err = GetLastError
    ' end if
    
    
    ' typedef enum _NORM_FORM {
    ' NormalizationOther  = 0,
    ' NormalizationC      = 0x1,
    ' NormalizationD      = 0x2,
    ' NormalizationKC     = 0x5,
    ' NormalizationKD     = 0x6
    ' } NORM_FORM;
    
  #else
    
    dim exc as new UnsupportedOperationException
    exc.message = "Normalize is not supported on this platform"
    raise exc
    
  #endif
  
End Function

I confirm the issue. However, it seems the WebPicture constructor works just fine :

dim f as FolderItem = SpecialFolder.desktop.child("rü.png") dim p as new webpicture(f) ImageView1.picture = p

Edit : Well. Not so good. Does not work for jpg, where the bug you spotted before triggers a NOE on the picture.