【问题标题】:Extract an image from a PNG image using its background position [closed]使用背景位置从PNG图像中提取图像[关闭]
【发布时间】:2017-01-06 13:27:46
【问题描述】:

我想使用背景位置从 PNG 文件中提取一组图像(就像我们在 CSS 文件中所做的那样)。

主要的PNG文件是List Of Flags,我想分别获取每个国家的国旗。

Android 中是否有任何方法可以以编程方式提取这些标志?

谢谢,

【问题讨论】:

标签: java android image


【解决方案1】:


1.将文件加载到位图中

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
// selected_photo.setImageBitmap(bitmap);   // if you need


2.访问每个像素数组

int dstWidth = width of the flag rectangle;
int dstHeight = height of the flag rectangle;
int pixelArray[] = new int[dstWidth * dstHeight];

int startX = start X position of your flag;
int endX = end X position of your flag;
int startY = start Y position of your flag;
int endX = end Y position of your flag;

bitmap.getPixels(pixelArray, 0, startX, startX, startY, dstWidth, dstHeight);  


3. 创建一个带数组的小位图

Bitmap flag = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(pixelArray);

【讨论】:

  • 谢谢@Suhyeon Lee,我认为除了使用位图解码方法之外还有另一种解决方案,但没关系,我会看看这个解决方案是否适合我;)
猜你喜欢
  • 2021-10-09
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 2012-12-16
  • 1970-01-01
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
相关资源
最近更新 更多