How can I save an Image to a Unicode Path?

Just starting out? Need help? Post your questions and find answers here.
Michel_k17
User
User
Posts: 14
Joined: Sun Dec 14, 2003 4:57 am
Location: Wichita, Kansas
Contact:

How can I save an Image to a Unicode Path?

Post 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
Michel "K-17" Korwin-Szymanowski
Michel_k17
User
User
Posts: 14
Joined: Sun Dec 14, 2003 4:57 am
Location: Wichita, Kansas
Contact:

Post 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.
Michel "K-17" Korwin-Szymanowski
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Are you sure this is a PB problem?

I'm unable to save an image with that filename from ANY program.

cheers
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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?
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

:shock:

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. :cry: (one or the other but I used to have both)

Thanks Trond. I have some testing to do.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Post 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
Post Reply