Wednesday, November 30, 2016

Black Background on Combined Images

I was asked to research about a strange behavior when we combine two images, each image becomes small and the rest of the extra space is filled with black color. After doing a bit of research and making sample applications, I found out that it has something to do with image dpi.

Each image is scanned with 240 dpi while Windows default to 96 dpi. That means, the image is scaled down, so I simply get the least dpi and set it as dpi for the combined image. It works for now, though I can see the potential problem if somehow the horizontal and vertical dpi are different.


Dim image1 As Bitmap = ...(code to get image) --> has 240 dpi
Dim image2 As Bitmap = ...(code to get image) --> has 240 dpi

Dim combinedImage As New Bitmap(...) --> default to 96 dpi

Dim horizontalResolution As Single = Math.Min(image1.HorizontalResolution, image2.HorizontalResolution)
Dim verticalResolution As Single = Math.Min(image1.VerticalResolution, image2.VerticalResolution)

combinedImage.SetResolution(horizontalResolution, verticalResolution)

Thursday, November 10, 2016

IdentityServer AuthorizeAttribute

I attempted to use ResourceAuthorize attribute in my personal project which uses Thinktecture IdentityServer 3. When testing around, I suddenly realize not only ResourceAttribute is not working, the AuthorizeAttribute was broken as well. Spent hours testing and finally found out that it was caused by a slash ("/") at the end of my issuer.

So "https://www.test.com/" does not work, but "https://www.test.com" works somehow. The AuthorizeAttribute now works but at this time, I'm still checking why troubleshooting my ResourceAttribute.

Edit: Apparently my ResourceAttribute was not working because one of the scopes is invalid and my intended scope is after that which eventually was not processed. And the requested claims will be included in the access_token.