Y at-il Anyway à afficher une partie d'une grande image - l'image est 16000 * 320 Lorsque j'ai essayé cela dans Android Studio en utilisant ImageView, je peux généralement obtenir ce qui ressemble à son travail activity_main.xml Conception, jusqu'à ce que je construise .apk puis l'image disparaît et en cours d'exécution sur ma tablette, il est également vide.Android - Afficher une partie d'une grande image
Répondre
Ajouter un ImageView dans votre mise en page fichier xml:
<ImageView
android:id="@+id/myImage"
android:layout_width="100dp"
android:layout_height="100dp"/>
Dans votre activité:
ImageView mImageView = (ImageView) findViewById(R.id.myImage);
Et puis utilisez BitmapRegionDecoder
:
// Get image width and height:
InputStream inputStream = getAssets().open("large_image.jpg");
BitmapFactory.Options tmpOptions = new BitmapFactory.Options();
tmpOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, tmpOptions);
int width = tmpOptions.outWidth;
int height = tmpOptions.outHeight;
// Crop image:
// Crop a rect with 200 pixel width and height from center of image
BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, false);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(width/2 - 100, height/2 - 100, width/2 + 100, height/2 + 100), options);
mImageView.setImageBitmap(bitmap);
code de here
Merci, je vais essayer cela ai-je besoin de quelque chose dans mon xml? –
Vous avez seulement besoin d'un 'ImageView' qui affichera l'image recadrée. La dernière ligne de l'exemple de code attribue l'image recadrée à 'mImageView' –
Merci d'avoir obtenu les problèmes suivants: - Ajout de mImageView comme identifiant de l'ImageView http://ibb.co/gXRO7F –
utilisation 'BitmapRegionDecoder' – pskink
Pourriez-vous ajouter du code? Comme le xml dans lequel vous ajoutez votre image? – MHogge
Merci pour la suggestion - mes fichiers xml ont été charges, y compris scrollview/imageview –