Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Dodaj Helper metodu da resize-a sliku na
- (http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp)
- public Image resizeImage(int newWidth, int newHeight, string stPhotoPath)
- {
- Image imgPhoto = Image.FromFile(stPhotoPath);
- int sourceWidth = imgPhoto.Width;
- int sourceHeight = imgPhoto.Height;
- //Consider vertical pics
- if (sourceWidth < sourceHeight)
- {
- int buff = newWidth;
- newWidth = newHeight;
- newHeight = buff;
- }
- int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
- float nPercent = 0, nPercentW = 0, nPercentH = 0;
- nPercentW = ((float)newWidth / (float)sourceWidth);
- nPercentH = ((float)newHeight / (float)sourceHeight);
- if (nPercentH < nPercentW)
- {
- nPercent = nPercentH;
- destX = System.Convert.ToInt16((newWidth -
- (sourceWidth * nPercent)) / 2);
- }
- else
- {
- nPercent = nPercentW;
- destY = System.Convert.ToInt16((newHeight -
- (sourceHeight * nPercent)) / 2);
- }
- int destWidth = (int)(sourceWidth * nPercent);
- int destHeight = (int)(sourceHeight * nPercent);
- Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
- PixelFormat.Format24bppRgb);
- bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
- imgPhoto.VerticalResolution);
- Graphics grPhoto = Graphics.FromImage(bmPhoto);
- grPhoto.Clear(Color.White);
- grPhoto.InterpolationMode =
- System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- grPhoto.DrawImage(imgPhoto,
- new Rectangle(destX, destY, destWidth, destHeight),
- new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
- GraphicsUnit.Pixel);
- grPhoto.Dispose();
- imgPhoto.Dispose();
- return bmPhoto;
- }
- 2. Vrati Base64 String sliku:
- string base64String = Convert.ToBase64String(imageBytes);
- (http://stackoverflow.com/questions/10889764/how-to-convert-bitmap-to-a-base64-string)
- 3. Napravi helper klasu koja ce kreirati tokene, i dekodirati ih:
- (http://stackoverflow.com/questions/14643735/how-to-generate-a-unique-token-which-expires-after-24-hours)
- - To create a unique token:
- string token = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
- - Basic example of creating a unique token containing a time stamp:
- byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
- byte[] key = Guid.NewGuid().ToByteArray();
- string token = Convert.ToBase64String(time.Concat(key).ToArray());
- - To decode the token to get the creation time:
- byte[] data = Convert.FromBase64String(token);
- DateTime when = DateTime.FromBinary(BitConverter.ToInt64(data, 0));
- if (when < DateTime.UtcNow.AddHours(-24)) {
- // too old
- }
- 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.
- *********NAPOMENA*******************
- 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).
- 4. Napravi token tabelu "UserToken" u bazi sa slijedecim parametrima:
- UserTokenId LONG identity ON not nullable PK
- UserId LONG not nullable FK
- TokenValue NVARCHAR(255) not nullable
- Created DATETIME not nullable
- 5. android studio listview with images
- http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/
- https://www.youtube.com/watch?v=HRPpQw0dzko
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement