-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImage.cpp
70 lines (55 loc) · 1.73 KB
/
Image.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Image.cpp
// Groozim
//
// Created by John Zakharov on 25.11.16.
// Copyright © 2016 Outlaw Studio. All rights reserved.
//
#include "Image.hpp"
#include "Mitsoko/AndroidUtil/java/io/FileOutputStream.hpp"
#include "Mitsoko/AndroidUtil/java/io/File.hpp"
#include "Mitsoko/AndroidUtil/java/io/BufferedOutputStream.hpp"
#include <iostream>
//#include "Services/Storage.hpp"
//using Services::Storage;
/*static void addToLog(const std::string &line) {
auto testData = Storage::shared().testData();
testData.push_back(line);
Storage::shared().setTestData(std::move(testData));
}*/
using java::io::File;
using java::io::BufferedOutputStream;
using java::io::FileOutputStream;
using android::graphics::Bitmap;
Mitsoko::Image::Image():image(){}
Mitsoko::Image::Image(decltype(image) image_):image(image_){}
Mitsoko::Image::operator bool() const {
return bool(image);
}
Mitsoko::Image::operator decltype(image) () {
return image;
}
void Mitsoko::Image::writeToFile(const std::string &filepath) {
#ifdef __APPLE__
if(auto i = image) {
if(auto data = UI::Image::JPEGRepresentation(i, 0.85)) {
auto done = data.writeToFile(filepath, true);
if(!done) {
std::cerr << "Viper::Image: write to file failed" << std::endl;
}
}
}
#else
if(auto i = image) {
auto file = File::create(filepath);
auto os = BufferedOutputStream::create(FileOutputStream::create(file));
// auto compressFormat = Bitmap::CompressFormat::JPEG();
auto compressFormat = Bitmap::CompressFormat::PNG();
i.compress(compressFormat, 85, os);
os.close();
}
#endif //__APPLE__
}
auto Mitsoko::Image::get() -> decltype(image) {
return image;
}