gtkD load images
Mike Wey via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 5 13:30:58 PDT 2017
On 05-08-17 15:23, Johnson Jones wrote:
> On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:
>> On 03-08-17 21:56, Johnson Jones wrote:
>>> If I do something like
>>>
>>> import gdkpixbuf.Pixbuf;
>>> Pixbuf.newFromResource("C:\\a.jpg");
>>
>> There are two issues here, you need to properly escape the slash:
>> "C:\\\\a.jpg".
>>
>> And a.jpg is not a resource file, so you would use the Pixbuf
>> constuctor to load an image file.
>>
>> ```
>> Pixbuf p = new Pixbuf(r"C:\\a.jpg");
>> ```
>
> Thanks. Why do I need 4 slashes? Is that standard with gtk because
> strings are interpreted twice or something? Seemed to work though.
>
>
Nothing specific to GTK but in D and other programing languages the \ is
used as an escape character, so you can use special characters in your
sting like `\n` for a newline. But this means you will need to use \\ to
get an literal back slash.
https://dlang.org/spec/lex.html#double_quoted_strings
You can also use an wysiwyg string by using `r"` at the start so what
you type is what you get.
https://dlang.org/spec/lex.html#wysiwyg
--
Mike Wey
More information about the Digitalmars-d-learn
mailing list