当前位置: 首页>>代码示例>>Java>>正文


Java ImageUtils类代码示例

本文整理汇总了Java中org.matrix.androidsdk.util.ImageUtils的典型用法代码示例。如果您正苦于以下问题:Java ImageUtils类的具体用法?Java ImageUtils怎么用?Java ImageUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ImageUtils类属于org.matrix.androidsdk.util包,在下文中一共展示了ImageUtils类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onActivityResult

import org.matrix.androidsdk.util.ImageUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_IMAGE) {
        if (resultCode == RESULT_OK) {

            this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    final LinearLayout linearLayout = mLinearLayoutByMatrixId.get(mUpdatingSessionId);

                    // sanity checks
                    if (null != linearLayout) {
                        ImageView avatarView = (ImageView) linearLayout.findViewById(R.id.imageView_avatar);

                        Uri imageUri = data.getData();
                        Bitmap thumbnailBitmap = null;
                        Uri scaledImageUri = data.getData();

                        try {
                            ResourceUtils.Resource resource = ResourceUtils.openResource(SettingsActivity.this, imageUri);

                            // with jpg files
                            // check exif parameter and reduce image size
                            if ("image/jpg".equals(resource.mimeType) || "image/jpeg".equals(resource.mimeType)) {
                                InputStream stream = resource.contentStream;
                                int rotationAngle = ImageUtils
                                        .getRotationAngleForBitmap(SettingsActivity.this, imageUri);

                                String mediaUrl = ImageUtils.scaleAndRotateImage(SettingsActivity.this, stream, resource.mimeType, 1024, rotationAngle, SettingsActivity.this.mMediasCache);
                                scaledImageUri = Uri.parse(mediaUrl);
                            } else {
                                ContentResolver resolver = getContentResolver();

                                List uriPath = imageUri.getPathSegments();
                                long imageId = -1;
                                String lastSegment = (String) uriPath.get(uriPath.size() - 1);

                                // > Kitkat
                                if (lastSegment.startsWith("image:")) {
                                    lastSegment = lastSegment.substring("image:".length());
                                }

                                imageId = Long.parseLong(lastSegment);
                                thumbnailBitmap = MediaStore.Images.Thumbnails.getThumbnail(resolver, imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
                            }

                            resource.contentStream.close();

                        } catch (Exception e) {
                            Log.e(LOG_TAG, "MediaStore.Images.Thumbnails.getThumbnail " + e.getMessage());
                        }

                        if (null != thumbnailBitmap) {
                            avatarView.setImageBitmap(thumbnailBitmap);
                        } else {
                            avatarView.setImageURI(scaledImageUri);
                        }

                        mTmpThumbnailUriByMatrixId.put(mUpdatingSessionId, scaledImageUri);

                        final Button saveButton = (Button) linearLayout.findViewById(R.id.button_save);
                        saveButton.setEnabled(true); // Enable the save button if it wasn't already
                    }
                }
            });
        }

        mUpdatingSessionId = null;
    }
}
 
开发者ID:matrix-org,项目名称:matrix-android-console,代码行数:72,代码来源:SettingsActivity.java

示例2: getThumbnailUriFromIntent

import org.matrix.androidsdk.util.ImageUtils; //导入依赖的package包/类
/**
 * Return a selected bitmap from an intent.
 *
 * @param intent the intent
 * @return the bitmap uri
 */
@SuppressLint("NewApi")
public static Uri getThumbnailUriFromIntent(Context context, final Intent intent, MXMediasCache mediasCache) {
    // sanity check
    if ((null != intent) && (null != context) && (null != mediasCache)) {
        Uri thumbnailUri = null;
        ClipData clipData = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            clipData = intent.getClipData();
        }

        // multiple data
        if (null != clipData) {
            if (clipData.getItemCount() > 0) {
                thumbnailUri = clipData.getItemAt(0).getUri();
            }
        } else if (null != intent.getData()) {
            thumbnailUri = intent.getData();
        }

        if (null != thumbnailUri) {
            try {
                ResourceUtils.Resource resource = ResourceUtils.openResource(context, thumbnailUri, null);

                // sanity check
                if ((null != resource) && resource.isJpegResource()) {
                    InputStream stream = resource.mContentStream;
                    int rotationAngle = ImageUtils.getRotationAngleForBitmap(context, thumbnailUri);

                    Log.d(LOG_TAG, "## getThumbnailUriFromIntent() :  " + thumbnailUri + " rotationAngle " + rotationAngle);

                    String mediaUrl = ImageUtils.scaleAndRotateImage(context, stream, resource.mMimeType, 1024, rotationAngle, mediasCache);
                    thumbnailUri = Uri.parse(mediaUrl);
                } else if (null != resource) {
                    Log.d(LOG_TAG, "## getThumbnailUriFromIntent() : cannot manage " + thumbnailUri + " mMimeType " + resource.mMimeType);
                } else {
                    Log.d(LOG_TAG, "## getThumbnailUriFromIntent() : cannot manage " + thumbnailUri + " --> cannot open the dedicated file");
                }

                return thumbnailUri;
            } catch (Exception e) {
                Log.e(LOG_TAG, "## getThumbnailUriFromIntent failed " + e.getMessage());
            }
        }
    }

    return null;
}
 
开发者ID:vector-im,项目名称:riot-android,代码行数:55,代码来源:VectorUtils.java

示例3: buildImageMessage

import org.matrix.androidsdk.util.ImageUtils; //导入依赖的package包/类
/**
 * Build an image message from a RoomMediaMessage.
 *
 * @param roomMediaMessage the roomMediaMessage
 * @return the image message
 */
private Message buildImageMessage(RoomMediaMessage roomMediaMessage) {
    try {
        String mimeType = roomMediaMessage.getMimeType(mContext);
        final MXMediasCache mediasCache = mDataHandler.getMediasCache();

        String mediaUrl = getMediaUrl(roomMediaMessage);

        // compute the thumbnail
        Bitmap thumbnailBitmap = roomMediaMessage.getFullScreenImageKindThumbnail(mContext);

        if (null == thumbnailBitmap) {
            thumbnailBitmap = getMediasPickerThumbnail(roomMediaMessage);
        }

        if (null == thumbnailBitmap) {
            Pair<Integer, Integer> thumbnailSize = roomMediaMessage.getThumnailSize();
            thumbnailBitmap = ResourceUtils.createThumbnailBitmap(mContext, roomMediaMessage.getUri(), thumbnailSize.first, thumbnailSize.second);
        }

        if (null == thumbnailBitmap) {
            thumbnailBitmap = roomMediaMessage.getMiniKindImageThumbnail(mContext);
        }

        String thumbnailURL = null;

        if (null != thumbnailBitmap) {
            thumbnailURL = mediasCache.saveBitmap(thumbnailBitmap, null);
        }

        // get the exif rotation angle
        final int rotationAngle = ImageUtils.getRotationAngleForBitmap(mContext, Uri.parse(mediaUrl));

        if (0 != rotationAngle) {
            // always apply the rotation to the image
            ImageUtils.rotateImage(mContext, thumbnailURL, rotationAngle, mediasCache);
        }

        ImageMessage imageMessage = new ImageMessage();
        imageMessage.url = mediaUrl;
        imageMessage.body = roomMediaMessage.getFileName(mContext);

        if (TextUtils.isEmpty(imageMessage.body)) {
            imageMessage.body = "Image";
        }

        Uri imageUri = Uri.parse(mediaUrl);

        if (null == imageMessage.info) {
            Room.fillImageInfo(mContext, imageMessage, imageUri, mimeType);
        }

        if ((null != thumbnailURL) && (null != imageMessage.info) && (null == imageMessage.info.thumbnailInfo)) {
            Uri thumbUri = Uri.parse(thumbnailURL);
            Room.fillThumbnailInfo(mContext, imageMessage, thumbUri, "image/jpeg");
            imageMessage.info.thumbnailUrl = thumbnailURL;
        }

        return imageMessage;
    } catch (Exception e) {
        Log.e(LOG_TAG, "## buildImageMessage() failed " + e.getMessage());
    }

    return null;
}
 
开发者ID:matrix-org,项目名称:matrix-android-sdk,代码行数:71,代码来源:RoomMediaMessagesSender.java


注:本文中的org.matrix.androidsdk.util.ImageUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。