diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2016-06-21 15:42:39 -0700 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2016-06-22 14:11:37 -0700 |
commit | 4cbaff6be1117f32c9706657b3f27c6f77e76492 (patch) | |
tree | 2ea28a3a822a939f21cf84e022e46882ff589750 /apct-tests/perftests/utils | |
parent | 23d1fdded5fe78024927137ddfb82401fd9e3344 (diff) |
Create BitmapUtils class for performance apct tests
b/28980976
Change-Id: I3c625f336b6e89352b3906244479da184858cc83
Diffstat (limited to 'apct-tests/perftests/utils')
-rw-r--r-- | apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java b/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java new file mode 100644 index 000000000000..4d0d97196241 --- /dev/null +++ b/apct-tests/perftests/utils/src/android/perftests/utils/BitmapUtils.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.perftests.utils; + +import android.content.Context; +import android.graphics.Bitmap; +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +public class BitmapUtils { + private static final String TAG = "BitmapUtils"; + + public static void saveBitmapIntoPNG(Context context, Bitmap bitmap, int resId) throws IOException { + // Save the image to the disk. + FileOutputStream out = null; + try { + String originalFilePath = context.getResources().getString(resId); + File originalFile = new File(originalFilePath); + String fileFullName = originalFile.getName(); + String fileTitle = fileFullName.substring(0, fileFullName.lastIndexOf(".")); + + File externalFilesDir = context.getExternalFilesDir(null); + File outputFile = new File(externalFilesDir, fileTitle + "_generated.png"); + if (!outputFile.exists()) { + outputFile.createNewFile(); + } + + out = new FileOutputStream(outputFile, false); + bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); + Log.v(TAG, "Write test No." + outputFile.getAbsolutePath() + " to file successfully."); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (out != null) { + out.close(); + } + } + } +} |