Advertisement
uraharadono

URADI VECERAS

Mar 28th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. 1. Dodaj Helper metodu da resize-a sliku na
  2.  
  3. (http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp)
  4. public Image resizeImage(int newWidth, int newHeight, string stPhotoPath)
  5. {
  6. Image imgPhoto = Image.FromFile(stPhotoPath);
  7.  
  8. int sourceWidth = imgPhoto.Width;
  9. int sourceHeight = imgPhoto.Height;
  10.  
  11. //Consider vertical pics
  12. if (sourceWidth < sourceHeight)
  13. {
  14. int buff = newWidth;
  15.  
  16. newWidth = newHeight;
  17. newHeight = buff;
  18. }
  19.  
  20. int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
  21. float nPercent = 0, nPercentW = 0, nPercentH = 0;
  22.  
  23. nPercentW = ((float)newWidth / (float)sourceWidth);
  24. nPercentH = ((float)newHeight / (float)sourceHeight);
  25. if (nPercentH < nPercentW)
  26. {
  27. nPercent = nPercentH;
  28. destX = System.Convert.ToInt16((newWidth -
  29. (sourceWidth * nPercent)) / 2);
  30. }
  31. else
  32. {
  33. nPercent = nPercentW;
  34. destY = System.Convert.ToInt16((newHeight -
  35. (sourceHeight * nPercent)) / 2);
  36. }
  37.  
  38. int destWidth = (int)(sourceWidth * nPercent);
  39. int destHeight = (int)(sourceHeight * nPercent);
  40.  
  41.  
  42. Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
  43. PixelFormat.Format24bppRgb);
  44.  
  45. bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
  46. imgPhoto.VerticalResolution);
  47.  
  48. Graphics grPhoto = Graphics.FromImage(bmPhoto);
  49. grPhoto.Clear(Color.White);
  50. grPhoto.InterpolationMode =
  51. System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  52.  
  53. grPhoto.DrawImage(imgPhoto,
  54. new Rectangle(destX, destY, destWidth, destHeight),
  55. new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
  56. GraphicsUnit.Pixel);
  57.  
  58. grPhoto.Dispose();
  59. imgPhoto.Dispose();
  60.  
  61. return bmPhoto;
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. 2. Vrati Base64 String sliku:
  70. string base64String = Convert.ToBase64String(imageBytes);
  71. (http://stackoverflow.com/questions/10889764/how-to-convert-bitmap-to-a-base64-string)
  72.  
  73.  
  74.  
  75.  
  76. 3. Napravi helper klasu koja ce kreirati tokene, i dekodirati ih:
  77. (http://stackoverflow.com/questions/14643735/how-to-generate-a-unique-token-which-expires-after-24-hours)
  78.  
  79. - To create a unique token:
  80. string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
  81.  
  82. - Basic example of creating a unique token containing a time stamp:
  83. byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
  84. byte[] key = Guid.NewGuid().ToByteArray();
  85. string token = Convert.ToBase64String(time.Concat(key).ToArray());
  86.  
  87. - To decode the token to get the creation time:
  88. byte[] data = Convert.FromBase64String(token);
  89. DateTime when = DateTime.FromBinary(BitConverter.ToInt64(data, 0));
  90. if (when < DateTime.UtcNow.AddHours(-24)) {
  91. // too old
  92. }
  93.  
  94. Note: If you need the token with the time stamp to be secure, you need to encrypt it. Otherwise a user could figure out what it contains and create a false token.
  95.  
  96. *********NAPOMENA*******************
  97. KAO STO JE OVAJ FRAJER REKAO - ISKORISTI CRYPTOHELPERS KLASU DA JOS JEDNOM ENKRIPTUJES OVAJ TOKEN (nadji salt ili korisnikov mail (da bi bilo jos unique) ili vrijednost iz web.config).
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. 4. Napravi token tabelu "UserToken" u bazi sa slijedecim parametrima:
  106. UserTokenId LONG identity ON not nullable PK
  107. UserId LONG not nullable FK
  108. TokenValue NVARCHAR(255) not nullable
  109. Created DATETIME not nullable
  110.  
  111.  
  112.  
  113. 5. android studio listview with images
  114. http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/
  115. https://www.youtube.com/watch?v=HRPpQw0dzko
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement