내 안드로이드 프로젝트에서, 이미지를 폰에서로드합니다. 그런 다음 자르기, 크기 조정, 픽셀 값 편집과 같은 다양한 이미지 조작을 수행합니다.android에서 ARGB_8888 비트 맵을 설정하는 방법은 무엇입니까?
하지만 문제는 비트 맵 형식이 ARGB_8888이 아니기 때문에 알파 값을 실제로 저장하지 않는 것입니다. 아니면 항상 255로 유지하고 있습니다.
어떻게 ARGB_8888 형식으로 비트 맵을로드 할 수 있습니까? 로드하고 크기를 조정하는 코드입니다. 이러한 형식으로 어떻게 형식을 지정할 수 있습니까?
감사
private static Bitmap resize(Bitmap img, int newW, int newH) throws IOException {
Bitmap resizedImg = Bitmap.createScaledBitmap(img, newW, newH, false);
img.recycle();
Bitmap newresizedImg = resizedImg.copy(Bitmap.Config.ARGB_8888, true);
resizedImg.recycle();
Pixel initialPixel = Function.getPixel(0, 0, newresizedImg, null);
int a = initialPixel.getColor().getAlpha(); // -> 255
newresizedImg.setPixel(0, 0, Pixel.getTransparentColor().getRGB());
initialPixel = Function.getPixel(0, 0, newresizedImg, null);
int new_a = initialPixel.getColor().getAlpha(); // -> 255
return newresizedImg;
}
private static Bitmap getImage(String from) throws IOException {
File file = new File(from);
if (file.exists()) {
BitmapFactory.Options op = new BitmapFactory.Options();
op.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bufferedImage = BitmapFactory.decodeFile(from, op);
return bufferedImage;
}
return null;
}
픽셀 클래스
public static Color getTransparentColor() {
return new Color(0, 0, 0, 0);
}
Color 클래스
public int getRGB() {
return ((A << 24) | 0xFF) + ((R << 16) | 0xFF) + ((G << 8) | 0xFF) + (B | 0xFF);
}
크기를 조정할 때 알파 지원을 잃어버린 것 같습니다. 어떻게 해결할 수 있습니까? – omega
크기 조정에 사용 된 코드가 알파 지원을 잃어서는 안됩니다. – TehCoder
코드가 위에 있습니다 .... – omega