728x90
안녕하세요
오늘은 PhotoEditor 라이브러리 사용하여 이미지 편집을 해보도록 하겠습니다.
PhotoEditor 라이브러리는 텍스트 추가, 드로잉, 이미지 추가, 필터 적용, 이모지 추가 등 다양한 기능을 지원하는 라이브러리 입니다.
이 중, 텍스트 추가 및 드로잉 기능을 구현해보도록 하겠습니다.
전체 코드 입니다.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ja.burhanrashid52.photoeditor.PhotoEditorView
android:id="@+id/photoEditorView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:photo_src="@drawable/cat1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true"
android:padding="16dp">
<Button
android:id="@+id/btn_add_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="텍스트 추가" />
<Button
android:id="@+id/btn_draw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="그리기"
android:layout_marginLeft="16dp" />
</LinearLayout>
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private PhotoEditor photoEditor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PhotoEditorView photoEditorView = findViewById(R.id.photoEditorView);
Button btnAddText = findViewById(R.id.btn_add_text);
Button btnDraw = findViewById(R.id.btn_draw);
// PhotoEditor 초기화
photoEditor = new PhotoEditor.Builder(this, photoEditorView)
.setPinchTextScalable(true) // 텍스트 크기 조절 가능
.build();
// 텍스트 추가
btnAddText.setOnClickListener(v -> {
TextStyleBuilder styleBuilder = new TextStyleBuilder();
styleBuilder.withTextColor(getResources().getColor(android.R.color.holo_blue_dark));
photoEditor.addText("안녕하세요!", styleBuilder);
});
// 그리기 모드 활성화
btnDraw.setOnClickListener(v -> {
photoEditor.setBrushDrawingMode(true);
photoEditor.setBrushColor(getResources().getColor(android.R.color.holo_red_dark));
photoEditor.setBrushSize(10f); // 브러시 크기 설정
});
}
}
이렇게 기본적인 텍스트 추가, 드로잉 모드 기능을 구현했습니다.
상세한 내용은
https://github.com/burhanrashid52/PhotoEditor?tab=readme-ov-file
GitHub - burhanrashid52/PhotoEditor: A Photo Editor library with simple, easy support for image editing using paints,text,filter
A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories. - burhanrashid52/PhotoEditor
github.com
해당 깃허브의 README 를 참고하여 응용해서 사용하시면 됩니다!
시연 영상입니다.
'안드로이드 자바' 카테고리의 다른 글
[Android][JAVA] TextView와 DynamicTextView 비교: 텍스트 레이아웃 처리의 차이점 (2) | 2024.12.19 |
---|---|
[Java][Android] TranslateAnimation을 활용한 텍스트 이동 애니메이션 (0) | 2024.12.18 |
[Java][Android] AlphaAnimation을 활용하여 글자 페이드 인/페이드 아웃 애니메이션 적용 (0) | 2024.12.12 |
[Java][Android] SeekBar 사용하여 값 나타내기 (0) | 2024.12.08 |
[Java][Android] Material Design Alert Dialog 사용하기 (0) | 2024.12.02 |