Last active
June 16, 2017 14:16
-
-
Save rdelrosario/4367b9cf92de4711de385d58878907f7 to your computer and use it in GitHub Desktop.
Apply Filter Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async void ApplyFilter(FilterType filterType) | |
{ | |
if (currentFilterType == filterType) | |
return; | |
var filterImage = Element as FilterImage; | |
//originalBitmap = await GetBitmapAsync(filterImage.OriginalSource); | |
using (Bitmap originalBitmap = await GetBitmapAsync(filterImage.OriginalSource)) | |
{ | |
var oldFilteredBitmap = filteredBitmap; | |
Bitmap bmp = null; | |
switch (filterType) | |
{ | |
case FilterType.NoFilter: | |
Element.Source = filterImage.OriginalSource; | |
bmp = originalBitmap; | |
break; | |
case FilterType.BlackAndWhite: | |
bmp = ApplyBlackAndWhite(originalBitmap); | |
break; | |
case FilterType.Hifi: | |
bmp = ApplyHiFi(originalBitmap); | |
break; | |
case FilterType.Saturated: | |
bmp = ApplySaturation(originalBitmap, 250); | |
break; | |
case FilterType.Vintage: | |
bmp = ApplyVignette(originalBitmap); | |
break; | |
} | |
filteredBitmap = filterType == FilterType.NoFilter ? null : bmp; | |
currentFilterType = filterType; | |
using (var resizedBitmap = bmp.ResizeBitmap(500, 500)) | |
{ | |
Control.SetImageBitmap(resizedBitmap); | |
} | |
oldFilteredBitmap?.Recycle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment