2014-08-29 4 views
0

내 안드로이드 프로젝트에서, 이미지를 폰에서로드합니다. 그런 다음 자르기, 크기 조정, 픽셀 값 편집과 같은 다양한 이미지 조작을 수행합니다.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); 
} 

답변

0

BitmapFactory.Options op = new BitmapFactory.Options(); op.inPreferredConfig = Bitmap.Config.ARGB_8888; bitmap = BitmapFactory.decodeFile(path, op);

에서 : How can I specify the bitmap format (e.g. RGBA_8888) with BitmapFactory.decode*()?

+0

크기를 조정할 때 알파 지원을 잃어버린 것 같습니다. 어떻게 해결할 수 있습니까? – omega

+0

크기 조정에 사용 된 코드가 알파 지원을 잃어서는 안됩니다. – TehCoder

+0

코드가 위에 있습니다 .... – omega

2

당신은 기능의이 유형을 사용하여 비트 맵을 복사 할 수 있습니다 (또는 당신이 그것을 사용하는 방법을 알고,에 따라 기능을 사용할 수 없습니다)

private Bitmap ARGBBitmap(Bitmap img) { 
    return img.copy(Bitmap.Config.ARGB_8888,true); 
} 
+0

시도했지만 시도하지 않았습니다. 위의 코드를 참조하십시오. – omega

+0

어떤 파일 형식으로 읽고 있습니까? 위의 코드와 매우 유사한 코드를 사용했습니다. 어떤 파일 형식입니까? 문제가있는 이미지 샘플을 제공 할 수 있습니까? 당신은 디버거를 사용하여 모든 getPixel 함수를 검사하여 예상 결과를 반환하는지 확인하십시오. – Grambot

0

이를 사용할 수 있습니다

public Bitmap highlightImage(Bitmap src) { 
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth() + 96, src.getHeight() + 96, Bitmap.Config.ARGB_8888); 
    return bmOut; 
} 
+0

왜 +96 높이와 너비입니까? – TehCoder

+0

+96을 사용할 필요가 없습니다. 이미지입니다. 필요한 목적입니다. – Soham

+0

오, 그건 나쁜 예입니다. – TehCoder

관련 문제