Tag Archives: c

Download image from url in C#

Simply You can use following methods.

using (WebClient client = new WebClient()) 
  {
    client.DownloadFile(new Uri(url), @"c:\temp\image35.png");

     //OR 

    client.DownloadFileAsync(new Uri(url), @"c:\temp\image35.png");
   }

If You don’t know the Format(.png, .jpeg etc) of Image

public void SaveImage(string filename, ImageFormat format) {

    WebClient client = new WebClient();
    Stream stream = client.OpenRead(imageUrl);
    Bitmap bitmap;  bitmap = new Bitmap(stream);

    if (bitmap != null) 
      bitmap.Save(filename, format);

    stream.Flush();
    stream.Close();
    client.Dispose();
}

References
https://stackoverflow.com/questions/24797485/how-to-download-image-from-url

Configure CMake to use GLIB

cmake_minimum_required(VERSION 3.8)
project(msync_server)

FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(GLIB glib-2.0)

include_directories(${GLIB_INCLUDE_DIRS})
link_directories(${GLIB_LIBRARY_DIRS})
add_definitions(${GLIB_CFLAGS_OTHER})

set(CMAKE_C_STANDARD 99)

set(SOURCE_FILES main.c)
add_executable(msync_server ${SOURCE_FILES} ${Glib_LIBRARY})

References
https://github.com/gammu/gammu/blob/master/cmake/FindGlib.cmake

Xamarin.Android Intellisense not working in Visual Studio

You can get those files from the above links, Just download it and those files move it manually to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Xml\Schemas or simply just add these schemas within Visual Studio.

https://github.com/atsushieno/monodroid-schema-gen/blob/master/android-layout-xml.xsd
https://github.com/atsushieno/monodroid-schema-gen/blob/master/schemas.android.com.apk.res.android.xsd

References :

http://stackoverflow.com/questions/17245308/xamarin-android-intellisense-not-working-in-visual-studio-2010
https://forums.xamarin.com/discussion/60962/enable-intellisense-for-axml-missing-android-layout-xml-xsd-schemas-android-com-apk-res-androiod

Configure CMake to use GTK

First install libgtk-3-dev and libgtkmm-3.0-dev then :

cmake_minimum_required(VERSION 3.7)
project(project1)

include(FindPkgConfig)
pkg_check_modules(GTK REQUIRED "gtk+-3.0")

include_directories(${GTK_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})

set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${GTK3_LIBRARIES})

References :

http://stackoverflow.com/questions/27514291/how-to-add-compiler-arguments-using-cmake

GCC -fpic option

-fpic

Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC, 28k on AArch64 and 32k on the m68k and RS/6000. The x86 has no such limit.)

Position-independent code requires special support, and therefore works only on certain machines. For the x86, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.

When this flag is set, the macros __pic__ and __PIC__ are defined to 1.

from Wikipedia :

In computing, position-independent code (PIC) or position-independent executable (PIE) is a body of machine code that, being placed somewhere in the primary memory, executes properly regardless of its absolute address. PIC is commonly used for shared libraries, so that the same library code can be loaded in a location in each program address space where it will not overlap any other uses of memory (for example, other shared libraries)

Example :

swig -python hello.i
gcc -fpic -c hellomodule.c hello_wrap.c -I/usr/include/python3.4/
gcc -shared hellomodule.o hello_wrap.o -o _hello.so

References :

https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html https://en.wikipedia.org/wiki/Position-independent_code

GCC -shared option

-shared
Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options used for compilation (-fpic, -fPIC, or model suboptions) when you specify this linker option.

Example :

gcc -fpic -c hellomodule.c hello_wrap.c -I/usr/include/python3.4/
gcc -shared hellomodule.o hello_wrap.o -o _hello.so

Reference :

https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html

GCC -o file option

-o file

Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.

Example :

gcc -shared hellomodule.o hello_wrap.o -o _hello.so

References :

https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html