Image resizing

Is there any C# code for cross-platform that would be similar to this:
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);

Or do I need to write separate code for iOS and Android?

Thanks!

Posts

  • GazpGazp USMember, Beta

    I had a similar need and ended up writing platform specific code to accomplish the resize as there is no generic cross platform way to get thumbnails that I could find.

    To make use of the code I implement it for each platform using a single shared interface and then use an IoC container to 'inject' the implementation appropriate for the platform my code is running against, that way my cross platform shared code just calls my ImageService.SaveThumbnail() method and the appropriate platform code is used to save a thumbnail (in my case).

    Hope that helps

  • PaulKeefePaulKeefe USMember ✭✭

    Thanks, Gareth. That's what I figured I might have to do but wanted to be sure before I wrote unneeded code.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @Tourist (nice name b.t.w. :smiley:), @Gazp and at all other readers of this thread:

    In my app, I have to resize images (before sending it via json-webservice to store it on a SQL-server).
    Therefore, I have found a basic-solution and changed / enhanced some code, so that it now works like need it.
    You find it here:

    https://forums.xamarin.com/discussion/37681/how-to-resize-an-image-in-xamarin-forms-ios-android-and-wp#latest

    Hope this helps :smiley:

  • PaulKeefePaulKeefe USMember ✭✭

    That looks great Fredy. I won't be able to give it a try at this time but it looks promising.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    You're welcome.
    I like, that you like it... :smiley:
    As I wrote, the base-solution is not from me (I only have enhanced it and changed some code).
    A big plus for me is, that it's easy and "clean" to integrate and you don't have to add some more platform-code...

Sign In or Register to comment.