Skip to content
Snippets Groups Projects
Commit 14b8aa77 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

profile: save account avatar in PNG

Change-Id: I4b83d669e337af60052040cf9f275c8fbf2e35f6
parent 9e8565b9
No related branches found
No related tags found
No related merge requests found
......@@ -253,7 +253,7 @@ typedef NS_ENUM(NSInteger, TagViews) {
returnCode:(NSInteger) code
contextInfo:(void*) contextInfo
{
//do nothing when editing canceled
//do nothing when editing canceled
if (code == 0) {
return;
}
......@@ -264,8 +264,12 @@ typedef NS_ENUM(NSInteger, TagViews) {
[photoView setImage: [outputImage roundCorners: outputImage.size.height * 0.5]];
[photoView setBordered:NO];
[addProfilePhotoImage setHidden:YES];
auto imageToBytes = QByteArray::fromNSData([outputImage TIFFRepresentation]).toBase64();
self.accountModel->setAvatar(self.selectedAccountID, QString(imageToBytes));
NSData* imageData = [outputImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData];
NSDictionary *properties = [[NSDictionary alloc] init];
imageData = [imageRep representationUsingType:NSPNGFileType properties: properties];
NSString * dataString = [imageData base64EncodedStringWithOptions:0];
self.accountModel->setAvatar(self.selectedAccountID, QString::fromNSString(dataString));
} else if(!photoView.image) {
[photoView setBordered:YES];
[addProfilePhotoImage setHidden:NO];
......
......@@ -98,8 +98,12 @@ typedef NS_ENUM(NSInteger, TagViews) {
outputImage = [outputImage imageResizeInsideMax: newSize];
[photoView setImage: [outputImage roundCorners: outputImage.size.height * 0.5]];
[addProfilePhotoImage setHidden:YES];
auto imageToBytes = QByteArray::fromNSData([outputImage TIFFRepresentation]).toBase64();
self.accountModel->setAvatar(self.selectedAccountID, QString(imageToBytes));
NSData* imageData = [outputImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData];
NSDictionary *properties = [[NSDictionary alloc] init];
imageData = [imageRep representationUsingType:NSPNGFileType properties: properties];
NSString * dataString = [imageData base64EncodedStringWithOptions:0];
self.accountModel->setAvatar(self.selectedAccountID, QString::fromNSString(dataString));
} else if(!photoView.image) {
[photoView setBordered:YES];
[addProfilePhotoImage setHidden:NO];
......
......@@ -85,8 +85,12 @@ NSTimer* timeoutTimer;
[self] (const QString& accountID) {
if([photoView image]) {
NSImage *avatarImage = [photoView image];
auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64();
self.accountModel->setAvatar(accountID, QString(imageToBytes));
NSData* imageData = [avatarImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData];
NSDictionary *properties = [[NSDictionary alloc] init];
imageData = [imageRep representationUsingType:NSPNGFileType properties: properties];
NSString * dataString = [imageData base64EncodedStringWithOptions:0];
self.accountModel->setAvatar(accountID, QString::fromNSString(dataString));
}
lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(accountID);
if(![serverField.stringValue isEqualToString:@""]) {
......
......@@ -269,8 +269,12 @@ BOOL isRendevous = false;
//set account avatar
if([photoView image]) {
NSImage *avatarImage = [photoView image];
auto imageToBytes = QByteArray::fromNSData([avatarImage TIFFRepresentation]).toBase64();
self.accountModel->setAvatar(accountID, QString(imageToBytes));
NSData* imageData = [avatarImage TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData: imageData];
NSDictionary *properties = [[NSDictionary alloc] init];
imageData = [imageRep representationUsingType:NSPNGFileType properties: properties];
NSString * dataString = [imageData base64EncodedStringWithOptions:0];
self.accountModel->setAvatar(accountID, QString::fromNSString(dataString));
}
//register username
if (self.registeredName && ![self.registeredName isEqualToString:@""]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment