반응형

요즘 자바의 Graphics을 이용하여, 유틸리티를 만들고 있습니다.


drawImage 함수의 경우 제목 표시줄을 제외하고 


실질적은 Graphics 프레임 영역에서 부터 0,0이 시작됩니다.


그런데 drawString은 제목 표시줄의 영역부터 0,0이 시작됩니다.


그래서 drawString을 0,0내 찍으면 제목표시줄에 가려서 보이지가 않습니다.



그냥 Y 좌표에 대략적으로 +10, +12 정도 주고 사용해도 되겠지만,


자바의 특성상 다른 OS에 갔을때 제목표시줄의 크기가 변할것 같은 찜찜함에 


해결 방법을 찾아봤습니다.


https://stackoverflow.com/questions/45227294/setting-drawstring-so-0-0-is-inside-the-draw-area

에서 해법을 찾았습니다.


기준의 위치를 바꿔주면 됩니다.



  FontMetrics fm = g.getFontMetrics();

    g.translate(0, fm.getAscent());

   

    Font font = new Font ("font/NanumBarunGothic.ttf", Font.PLAIN, fontSize); 

    g.setColor(color);

    g.setFont (font);

    g.drawString(str, x, y);

   

   

    g.translate(0, 0);


위와 같이 기준점을 fm.getAscent() 함수를 이용해 변경해서 drawString 글자를 찍고


다시 원래대로 g.translate(0, 0); 돌려줍니다. 


위와 같은 방법으로 문제를 해결했습니다.




반응형
반응형

Java만 열심히 하다가 C# 만질일이 있어서 만지던중


다차원 배열 초기화를 하다가 멘붕에 빠졌습니다. '-' ;;;;;;;


'-' 이런 모양의 초기화도 존재할수 있따니!!!! ㅋㅋㅋ 옛날 사람




// Two-dimensional array.
int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
// The same array with dimensions specified.
int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
// A similar array with string elements.
string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" },
                                        { "five", "six" } };

// Three-dimensional array.
int[, ,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, 
                                 { { 7, 8, 9 }, { 10, 11, 12 } } };
// The same array with dimensions specified.
int[, ,] array3Da = new int[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } }, 
                                       { { 7, 8, 9 }, { 10, 11, 12 } } };

// Accessing array elements.
System.Console.WriteLine(array2D[0, 0]);
System.Console.WriteLine(array2D[0, 1]);
System.Console.WriteLine(array2D[1, 0]);
System.Console.WriteLine(array2D[1, 1]);
System.Console.WriteLine(array2D[3, 0]);
System.Console.WriteLine(array2Db[1, 0]);
System.Console.WriteLine(array3Da[1, 0, 1]);
System.Console.WriteLine(array3D[1, 1, 2]);

// Getting the total count of elements or the length of a given dimension.
var allLength = array3D.Length;
var total = 1;
for (int i = 0; i < array3D.Rank; i++) {
    total *= array3D.GetLength(i);
}
System.Console.WriteLine("{0} equals {1}", allLength, total);




출처 : http://msdn.microsoft.com/ko-kr/library/2yd9wwz4.aspx



반응형
반응형

오랜만에 프로그래밍 관련 포스팅이군요 ^^



어제 프로그램을 짜다가 문득 써먹게 되어서


아 이걸 팁으로 포스팅 해야겠구나 ~


생각하게 됐습니다.


#pragma comment() <-- 요놈은


라이브러리 추가시에 가장 많이 쓰임니다.


간혹가다가 api프로젝트에서 디버깅을 위해 콘솔창을 띄우고 싶을때는
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console" )


이렇게 linker 을 쓰기도 하지만.


주로 프로젝트~ 셋팅~ 들어가서 라이브러리 일일이 추가하기 귀찮으실때


자주 씁니다.









#pragma comment( lib, "msimg32.lib")

이런식으로 씁니다.


비주얼 C++을 쓰면서 많이 쓰진 않지만 예전에는 라이브러리 추가시엔

저놈을 무조건 써야했습니다 ^^


그럼 유용하게 쓰세요.




반응형

+ Recent posts