Twidere-App-Android-Twitter.../twidere/src/main/java/org/mariotaku/twidere/util/BitmapUtils.java

58 lines
1.7 KiB
Java

/*
* Copyright (C) 2010 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 org.mariotaku.twidere.util;
import android.content.ContentResolver;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class BitmapUtils {
private BitmapUtils() {
}
@Nullable
public static String getImageMimeType(ContentResolver cr, final Uri uri) {
if (uri == null) return null;
final BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
InputStream is = null;
try {
is = cr.openInputStream(uri);
BitmapFactory.decodeStream(is, null, o);
return o.outMimeType;
} catch (IOException e) {
return null;
} finally {
Utils.closeSilently(is);
}
}
public static String getImageMimeType(final File image) {
if (image == null) return null;
final BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getPath(), o);
return o.outMimeType;
}
}