-1
我想從使用背景位置的PNG文件提取一組圖像(就像我們在CSS文件中那樣)。使用其背景位置從PNG圖像中提取圖像
主要的PNG文件是List Of Flags,我想分別獲得每個國家的國旗。
有沒有什麼辦法可以在Android中以編程方式提取這些標誌?
謝謝,
我想從使用背景位置的PNG文件提取一組圖像(就像我們在CSS文件中那樣)。使用其背景位置從PNG圖像中提取圖像
主要的PNG文件是List Of Flags,我想分別獲得每個國家的國旗。
有沒有什麼辦法可以在Android中以編程方式提取這些標誌?
謝謝,
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李,我認爲有另一種解決方案,而不是使用位圖解碼方法,但沒關係,我會看看這種解決方案是否適用於我;) –
解釋什麼是您的要求正確地創建一個小的位圖。沒有得到你想要的 – Nepster
使用https://developer.android.com/guide/topics/resources/drawable-resource.html#Clip進行剪輯 – Nepster
也看看http://stackoverflow.com/q/ 7341017/3496570 – Nepster