Page 1 of 1
How can I save an Image to a Unicode Path?
Posted: Wed Jan 30, 2008 6:19 am
by Michel_k17
Hi,
I have been trying to save a jpeg to a path that includes Japanese Characters. Unfortunately, the SaveImage call fails. Am I missing something?
Compiler settings are set to "Unicode" and the editor to UTF-8.
Thanks!
Code: Select all
Result.l
UseJPEGImageEncoder()
UseJPEGImageDecoder()
; Git da image
Result = LoadImage(0, "C:\Temp\Delme_1.jpg")
If Result = 0
MessageRequester("ERROR", "FAILED To LOAD")
Else
;Save it to Unicode path As a Jpeg. Will it work?
; ASCII
Result = SaveImage(0, "C:\Temp\Delme\MyPBTest.jpg", #PB_ImagePlugin_JPEG )
If Result = 0
MessageRequester("ERROR", "FAILED " + Str(GetErrorNumber()) + " - " + GetErrorDLL())
EndIf
; Japanese (this will fail - looks like Unicode is not supported)
Result = SaveImage(0, "C:\Temp\検索オプション\検索オプション.jpg", #PB_ImagePlugin_JPEG )
If Result = 0
; Recover the error
MessageRequester("ERROR", "FAILED "+Str(GetErrorNumber()) + " - " + GetErrorDLL())
EndIf
EndIf
End
Posted: Fri Feb 01, 2008 2:34 am
by Michel_k17
Anyone? Please? I have a new project that requires Japanese support, and I thought that PB4 now supported unicode strings. Does that mean it is true for strings, but not for the functions?
Thanks in advance for any help, or a workaround of any kind.
Posted: Fri Feb 01, 2008 2:43 am
by rsts
Are you sure this is a PB problem?
I'm unable to save an image with that filename from ANY program.
cheers
Posted: Fri Feb 01, 2008 3:58 am
by SFSxOI
検索オプション\検索オプション.jpg
So just guessing here...but maybe its because part of the string is in ascii, so...what you might have is a mixture of japaneese (or unicode?) and ascii??
is the development computer set up in japaneese? I assume you tried compiling in unicode also?
PB doesn't support japaneese does it?
Posted: Fri Feb 01, 2008 6:56 am
by pdwyer
How is the string going to get into the application? (hardcoded like the example, user input, read from some other source like a DB/file)?
If you app is compiled in unicode mode then user input will be received in unicode and things should work but hard coded strings will need conversion (multibite to wide char) from UTF8 (I can post code later to do that when I get home)
If the app is not unicode then you will be getting userinput in cp932, I can test whether the image save works with the chars when I get home too (no PB compiler at work).
Question: Does it need to work on PCs that don't have Japanese fonts installed? Will the systems be Japanese or english? If english will the regional settings be set to have non-unicode set to Japanese?
Unicode app will probably work best. you just need to convert your hardcoded text from UTF8 as wide chars (windows unicode mode) are utf16
Posted: Fri Feb 01, 2008 12:33 pm
by Trond
What pdwyer says is wrong. You don't need to convert from UTF-8, because PB strings are converted from UTF-8 automatically when the program is compiled. The exe file has only the UCS-2 strings.
I think your code should work as it is.
Posted: Fri Feb 01, 2008 12:48 pm
by pdwyer
I haven't tried this in 4.1 before, has this changed?
Previously in UTF8 (IDE) mode I'd type kanji in and in a
non unicode app and debugger it would display, now it doesn't, it works in plain text mode but the kanji won't display in the IDE anymore like that.

(one or the other but I used to have both)
Thanks Trond. I have some testing to do.
Posted: Fri Feb 01, 2008 1:03 pm
by pdwyer
ok, I lost a few settings when I down graded from the beta
I have fixed my little problem. Either way, Trond is right though, I didn't realise that these did the same thing.
Code: Select all
a.s = "日本語"
mem = AllocateMemory(1000)
PokeS(mem, a, -1, #PB_UTF8)
new.s = Space(1000)
Debug a
MultiByteToWideChar_(65001, 0, mem, -1, @new, 1000)
MessageRequester(new,new)
;=======================
a.s = "日本語"
MessageRequester(a,a)
Seems I've been taking a long cut
Posted: Fri Feb 01, 2008 2:07 pm
by pdwyer
Okay, I can get this code to work in two ways
1. UTF source code and Unicode mode
2. Plain text mode, normal mode
I get the error you get in UTF8 source and normal mode. I added an extra line of code to add the directory in.
CreateDirectory("C:\Temp\検索オプション")
I didn't notice the slash in the middle of that kensaku option bit.
When I change between source code types the code truncates so copy it somewhere, change the source code and then repaste it. You will need a japanese font selected as your source font to view it in plain text mode (ms mincho or something) in Unicode you can use anything (like courier new) and windows will add the kanji font when needed
hope this helps a little
Code: Select all
Result.l
UseJPEGImageEncoder()
UseJPEGImageDecoder()
; Git da image
Result = LoadImage(0, "C:\Temp\Delme_1.jpg")
If Result = 0
MessageRequester("ERROR", "FAILED To LOAD")
Else
;Save it to Unicode path As a Jpeg. Will it work?
; ASCII
Result = SaveImage(0, "C:\Temp\Delme\MyPBTest.jpg", #PB_ImagePlugin_JPEG )
If Result = 0
MessageRequester("ERROR", "FAILED " + Str(GetErrorNumber()) + " - " + GetErrorDLL())
EndIf
CreateDirectory("C:\Temp\検索オプション")
; Japanese (this will fail - looks like Unicode is not supported)
Result = SaveImage(0, "C:\Temp\検索オプション\検索オプション.jpg", #PB_ImagePlugin_JPEG )
If Result = 0
; Recover the error
MessageRequester("ERROR", "FAILED "+Str(GetErrorNumber()) + " - " + GetErrorDLL())
EndIf
EndIf
End
At least we know that the PB lib's save image is not the cause of this
Posted: Fri Feb 01, 2008 3:08 pm
by breeze4me
Maybe SaveImage() doesn't fully support unicode.
Instead of SaveImage, use this way. It's somewhat dirty way, i think.
Tested on UTF-8 source text and unicode compilation mode.
Code: Select all
Result.l
UseJPEGImageEncoder()
UseJPEGImageDecoder()
; Git da image
Result = LoadImage(0, "C:\Temp\Delme_1.jpg")
If Result = 0
MessageRequester("ERROR", "FAILED To LOAD")
Else
;Save it to Unicode path As a Jpeg. Will it work?
; ASCII
Result = SaveImage(0, "C:\Temp\Delme\MyPBTest.jpg", #PB_ImagePlugin_JPEG )
If Result = 0
MessageRequester("ERROR", "FAILED " + Str(GetErrorNumber()) + " - " + GetErrorDLL())
EndIf
CreateDirectory("C:\Temp\検索オプション") ;if there is no such folder.
ImageSize = 1024000
*ImageData = AllocateMemory(ImageSize)
hImageDataPipe = CreateNamedPipe_("\\.\pipe\ImageDataPipe", #PIPE_ACCESS_INBOUND|#FILE_FLAG_OVERLAPPED, #PIPE_TYPE_BYTE|#PIPE_READMODE_BYTE|#PIPE_NOWAIT, 1, ImageSize, ImageSize, #NMPWAIT_USE_DEFAULT_WAIT, 0)
If hImageDataPipe <> #INVALID_HANDLE_VALUE
SaveImage(0,"\\.\pipe\ImageDataPipe", #PB_ImagePlugin_JPEG)
ReadFile_(hImageDataPipe, *ImageData, ImageSize, @NewImageSize, 0)
CloseHandle_(hImageDataPipe)
If CreateFile(0, "C:\Temp\検索オプション\検索オプション.jpg")
WriteData(0, *ImageData, NewImageSize)
CloseFile(0)
FreeMemory(*ImageData)
Debug "ok"
EndIf
EndIf
; ; Japanese (this will fail - looks like Unicode is not supported)
; Result = SaveImage(0, "C:\Temp\検索オプション\検索オプション.jpg", #PB_ImagePlugin_JPEG )
; If Result = 0
; ; Recover the error
; MessageRequester("ERROR", "FAILED "+Str(GetErrorNumber()) + " - " + GetErrorDLL())
; EndIf
EndIf
End