[안드로이드]Bitmap black&white(흑백)만들기


안녕하세요 예지우랑입니다.


안드로이드 개발중에 이미지를 다루는것은 여간 귀찮은것이 아니지요

생각없이 비트맵에 불러왔다가 메모리 오류가 뜨는경우도 있고

다루다보면 마음대로 안되기 마련이죠 


오늘은 비트맵을 흑백으로 만드는 방법에대해 알려드리려합니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 *bitmap 흑백으로 변환
 */
    private Bitmap grayScale(final Bitmap orgBitmap){
        Log.i("gray""in");
        int width, height;
        width = orgBitmap.getWidth();
        height = orgBitmap.getHeight();
 
        Bitmap bmpGrayScale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
 
        // color information
        int A, R, G, B;
        int pixel;
 
        // scan through all pixels
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                // get pixel color
                pixel = orgBitmap.getPixel(x, y);
                A = Color.alpha(pixel);
                R = Color.red(pixel);
                G = Color.green(pixel);
                B = Color.blue(pixel);
                int gray = (int) (0.2989 * R + 0.5870 * G + 0.1140 * B);
 
                // use 128 as threshold, above -> white, below -> black
                if (gray > 128)
                    gray = 255;
                else
                    gray = 0;
                // set new pixel color to output bitmap
                bmpGrayScale.setPixel(x, y, Color.argb(A, gray, gray, gray));
            }
        }
        return bmpGrayScale;
 
    }
cs


비트맵에 이 소스를 적용하면 

정확하게 흑/백으로 나뉘게 됩니다.

처음에 이소스를 만든 이유는 혹시나 이렇게 흑백으로 만들면 

용량이 줄어들까 해서 만들어봤는데 

용량은 안줄어들더군요 ㅠㅠ

혹시 이미지 용량을 줄일 수 있는 방법을 알고계신 분 있으시다면 

댓글이나 메일 부탁드립니다 ㅠㅠ


감사합니다.



반응형

[apk 버전코드] 플레이 스토어에 apk 업로드시 버전코드 중복이나올경우



플래이스토어에 업로드를 했는데 

버전코드가 중복된다고 나오는 경우가 있습니다. 


이때 제일 먼저 확인해 봐야할것은 Manifast파일의 버전 코드죠

하지만 버전코드를 하나 올렸음에도 불구하고 

계속해서 같은 버전코드라고 나오는 경우가 있습니다. 

이떄는 

프로잭트폴더\app 아래에 있는 build.gradle을 확인해 보시기 바랍니다.

그곳에 버전코드와 버전 네임을 올려주시면 해결됩니다.

반응형

1. jQuery로 선택된 값 읽기

 

$("#selectBox option:selected").val();

$("select[name=name]").val();

 

2. jQuery로 선택된 내용 읽기

 

$("#selectBox option:selected").text();

 

3. 선택된 위치

 

var index = $("#test option").index($("#test option:selected"));

 

4. Add options to the end of a select

 

$("#selectBox").append("<option value='1'>Apples</option>");

$("#selectBox").append("<option value='2'>After Apples</option>");

 

5. Add options to the start of a select

 

$("#selectBox").prepend("<option value='0'>Before Apples</option>");

 

6. Replace all the options with new options

 

$("#selectBox").html("<option value='1'>Some oranges</option><option value='2'>MoreOranges</option>");

 

7. Replace items at a certain index

 

$("#selectBox option:eq(1)").replaceWith("<option value='2'>Someapples</option>");

$("#selectBox option:eq(2)").replaceWith("<option value='3'>Somebananas</option>");

 

8. 지정된 index값으로 select 하기

 

$("#selectBox option:eq(2)").attr("selected", "selected");

 

9. text 값으로 select 하기

 

$("#selectBox").val("Someoranges").attr("selected", "selected");

 

10. value값으로 select 하기

 

$("#selectBox").val("2");

 

11. 지정된 인덱스값의 item 삭제

 

$("#selectBox option:eq(0)").remove();

 

12. 첫번째 item 삭제

 

$("#selectBox option:first").remove();

 

13. 마지막 item 삭제

 

$("#selectBox option:last").remove();

 

14. 선택된 옵션의 text 구하기

 

alert(!$("#selectBox option:selected").text());

 

15. 선택된 옵션의 value 구하기

 

alert(!$("#selectBox option:selected").val());

 

16. 선택된 옵션 index 구하기

 

alert(!$("#selectBox option").index($("#selectBox option:selected")));

 

17. SelecBox 아이템 갯수 구하기

 

alert(!$("#selectBox option").size());

 

18. 선택된 옵션 앞의 아이템 갯수

 

alert(!$("#selectBox option:selected").prevAl!l().size());

 

19. 선택된 옵션 후의 아이템 갯수

 

alert(!$("#selectBox option:selected").nextAll().size());

 

20. Insert an item in after a particular position

 

$("#selectBox option:eq(0)").after("<option value='4'>Somepears</option>");

 

21. Insert an item in before a particular position

 

$("#selectBox option:eq(3)").before("<option value='5'>Someapricots</option>");

 

22. Getting values when item is selected

 

$("#selectBox").change(function(){

           alert(!$(this).val());

           alert(!$(this).children("option:selected").text());

});

반응형

'웹프로그래밍 > jQuery' 카테고리의 다른 글

jQuery 로 이미지 사이즈 구하기  (0) 2015.04.01
[jQuery] replace 사용시 팁  (0) 2014.07.16

+ Recent posts