Android:如何:创建现有位图的新副本? [英] Android: How to: create a new copy of an existing Bitmap?

查看:83
本文介绍了Android:如何:创建现有位图的新副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个简单的楼层地图指南.我有不同的楼层和对应的MAPS.楼层是按钮,MAPS是存储在sdcard中的png文件.当我单击1F时,将显示相应的1Fmap,以及其他楼层.

I will create a simple floor map guide. I have different FLOORS and the corresponding MAPS. FLOORS are buttons and MAPS are png files stored in the sdcard. When I click 1F and corresponding 1Fmap will be displayed and so with other floors.

我在考虑以下问题:

  1. 一个图像视图以显示所选地图.
  2. Hashmap(OR)处理位图.用于根据所选楼层获取位图.然后通过setImageBitmap(..)
  3. 设置为ImageView
  4. 在单击楼层按钮时,将下载要在哈希图中分配的位图.然后创建位图,将其设置为imageview,然后再单击其他楼层将其存储为哈希图.
  1. one image view to show the selected map.
  2. Hashmap ( OR ) to handle the bitmaps. use to obtain the bitmap based on the selected floor. then set to ImageView via setImageBitmap(..)
  3. the bitmap to be assigned in the Hashmap are downloaded upon clicking of the floor button. then create the bitmap, set to imageview and the later on store to hashmap upon clicking the other floors.

这是我的技术/设计问题:

Here are my technical/design problems:

  1. 如何创建位图的副本?
  2. 是否可以将其逐步存储到hashmap或每次单击地板按钮即可从sdcard获取?
  3. 如果我要使用哈希图,可以使用Integer(地板数字)或String(地板名称)作为地图键吗?

更新: 另外,我的目标是最多20个楼层(这意味着20个512x512 png文件...我还想按照其他建议将其调整为256x256).

UPDATE: additional, I am targeting maximum of 20 floors (it means 20 512x512 png files...i am thinking also to adjust it to 256x256 as others suggested).

推荐答案

  1. 要创建位图的副本,可以使用:

  1. To create copy of bitmap you can use:

Bitmap newBmp = Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter);

您可以逐渐从SD卡获取图像.此实现没有问题.

You can gradually get the Image from SD card. NO problem with this implementation.

如果您正在使用Hashmap,则可以将图像URL用作Hashmap的密钥.

If you are using Hashmap then you can user the image URL as the Key for Hashmap.

这篇关于Android:如何:创建现有位图的新副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆