Imagen은 이미지 생성 모델입니다. 사용자 프로필의 맞춤 아바타를 생성하거나 맞춤설정된 시각적 애셋을 기존 화면 흐름에 통합하여 사용자 참여도를 높이는 데 사용할 수 있습니다.
Firebase AI Logic SDK를 사용하여 Android 앱에서 Imagen 모델에 액세스할 수 있습니다. Imagen 모델은 Firebase AI Logic API 제공업체인 Gemini Developer API (대부분의 개발자에게 권장됨)와 Vertex AI를 모두 사용하여 사용할 수 있습니다.
그림 1.
Firebase AI Logic을 사용하여 Imagen 모델에 액세스합니다.
프롬프트 실험
이상적인 프롬프트를 만드는 데는 여러 번의 시도가 필요한 경우가 많습니다. 프롬프트 설계 및 프로토타입 제작을 위한 IDE인 Vertex AI Studio에서 이미지 프롬프트를 실험할 수 있습니다. 프롬프트를 개선하는 방법에 관한 도움말은 프롬프트 및 이미지 속성 가이드를 참고하세요.
그림 2.
Vertex AI Studio를 사용하면 이미지 생성 프롬프트를 미세 조정할 수 있습니다.
dependencies{// Import the BoM for the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.1.0"))// Add the dependency for the Firebase AI Logic library. When using the BoM,// you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-ai")}
이미지 생성
Android 앱에서 이미지를 생성하려면 먼저 구성(선택사항)을 사용하여 ImagenModel를 인스턴스화합니다.
generationConfig 매개변수를 사용하여 부정 프롬프트, 이미지 수, 출력 이미지 가로세로 비율, 이미지 형식을 정의하고 워터마크를 추가할 수 있습니다. safetySettings 매개변수를 사용하여 안전 및 사용자 필터를 구성할 수 있습니다.
Kotlin
valconfig=ImagenGenerationConfig{numberOfImages=2,aspectRatio=ImagenAspectRatio.LANDSCAPE_16x9,imageFormat=ImagenImageFormat.jpeg(compressionQuality=100),addWatermark=false}// Initialize the Gemini Developer API backend service// For Vertex AI use Firebase.ai(backend = GenerativeBackend.vertexAI())valmodel=Firebase.ai(backend=GenerativeBackend.googleAI()).imagenModel(modelName="imagen-3.0-generate-002",generationConfig=config,safetySettings=ImagenSafetySettings(safetyFilterLevel=ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,personFilterLevel=ImagenPersonFilterLevel.BLOCK_ALL))
자바
ImagenGenerationConfigconfig=newImagenGenerationConfig.Builder().setNumberOfImages(2).setAspectRatio(ImagenAspectRatio.LANDSCAPE_16x9).setImageFormat(ImagenImageFormat.jpeg(100)).setAddWatermark(false).build();// For Vertex AI use Firebase.ai(backend = GenerativeBackend.vertexAI())ImagenModelFuturesmodel=ImagenModelFutures.from(FirebaseAI.ai(backend=GenerativeBackend.googleAI()).imagenModel("imagen-3.0-generate-002",config,ImagenSafetySettings.builder().setSafetyFilterLevel(ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE).setPersonFilterLevel(ImagenPersonFilterLevel.BLOCK_ALL).build()));
ImagenModel가 인스턴스화되면 generateImages를 호출하여 이미지를 생성할 수 있습니다.
Kotlin
valimageResponse=model.generateImages(prompt="An astronaut riding a horse",)valimage=imageResponse.images.firstvalbitmapImage=image.asBitmap()
Java
CompletableFuture<GenerateContentResponse>futureResponse=model.generateContent(Content.newBuilder().addParts(Part.newBuilder().setText("An astronaut riding a horse").build()).build());try{GenerateContentResponseimageResponse=futureResponse.get();List<GeneratedImage>images=imageResponse.getCandidates(0).getContent().getParts(0).getInlineData().getImagesList();if(!images.isEmpty()){GeneratedImageimage=images.get(0);BitmapbitmapImage=image.asBitmap();// Use bitmapImage}}catch(ExecutionException|InterruptedExceptione){e.printStackTrace();}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-17(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-17(UTC)"],[],[],null,["# Generate images with Imagen\n\nImagen is an image generation model. It can be used to generate\ncustom avatars for user profiles or to integrate personalized visual assets into\nexisting screen flows to increase user engagement.\n\nYou can access [Imagen models](https://firebase.google.com/docs/vertex-ai/models) from your Android app using the\n[Firebase AI Logic SDK.](https://firebase.google.com/docs/vertex-ai/generate-images-imagen?platform=android) Imagen models are available using both\nFirebase AI Logic [API providers](/ai/gemini#api-providers): Gemini Developer API (recommended for most\ndevelopers) and Vertex AI.\n**Figure 1.** Access Imagen models using Firebase AI Logic. **Note:** Firebase AI Logic doesn't yet support all the features available for the server-side integrations of Imagen models. Learn more about the supported capabilities in the [Firebase documentation](https://firebase.google.com/docs/vertex-ai/generate-images-imagen?platform=android#capabilities-features).\n\nExperiment with prompts\n-----------------------\n\nCreating the ideal prompts often takes multiple attempts. You can experiment\nwith image prompts in [Vertex AI Studio](https://console.cloud.google.com/vertex-ai/generative/vision), an IDE for prompt\ndesign and prototyping. For tips on how to improve your prompts, review the\n[prompt and image attribute guide](https://cloud.google.com/vertex-ai/generative-ai/docs/image/img-gen-prompt-guide).\n**Figure 2.** Vertex AI Studio can help you refine your image generation prompts.\n\nSet up a Firebase project and connect your app\n----------------------------------------------\n\nFollow the steps in the Firebase documentation to\n[add Firebase to your Android project](https://firebase.google.com/docs/android/setup).\n\nAdd the Gradle dependency\n-------------------------\n\nAdd the following dependencies to your `build.gradle` file: \n\n dependencies {\n // Import the BoM for the Firebase platform\n implementation(platform(\"com.google.firebase:firebase-bom:34.1.0\"))\n\n // Add the dependency for the Firebase AI Logic library. When using the BoM,\n // you don't specify versions in Firebase library dependencies\n implementation(\"com.google.firebase:firebase-ai\")\n }\n\nGenerate an image\n-----------------\n\nTo generate an image in your Android app, start by instantiating an\n`ImagenModel` with an optional configuration.\n\nYou can use the [`generationConfig`](https://firebase.google.com/docs/vertex-ai/model-parameters?platform=android) parameter to define a negative prompt, the\nnumber of images, the output image aspect ratio, the image format and add a\nwatermark. You can use the [`safetySettings`](https://firebase.google.com/docs/vertex-ai/safety-settings?platform=android) parameter to configure the safety\nand person filters.\n**Note:** Refer to the Firebase documentation for up-to-date information about [available Imagen models](https://firebase.google.com/docs/vertex-ai/models). \n\n### Kotlin\n\n val config = ImagenGenerationConfig {\n numberOfImages = 2,\n aspectRatio = ImagenAspectRatio.LANDSCAPE_16x9,\n imageFormat = ImagenImageFormat.jpeg(compressionQuality = 100),\n addWatermark = false\n }\n\n // Initialize the Gemini Developer API backend service\n // For Vertex AI use Firebase.ai(backend = GenerativeBackend.vertexAI())\n val model = Firebase.ai(backend = GenerativeBackend.googleAI()).imagenModel(\n modelName = \"imagen-3.0-generate-002\",\n generationConfig = config,\n safetySettings = ImagenSafetySettings(\n safetyFilterLevel = ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,\n personFilterLevel = ImagenPersonFilterLevel.BLOCK_ALL\n )\n )\n\n### Java\n\n ImagenGenerationConfig config = new ImagenGenerationConfig.Builder()\n .setNumberOfImages(2)\n .setAspectRatio(ImagenAspectRatio.LANDSCAPE_16x9)\n .setImageFormat(ImagenImageFormat.jpeg(100))\n .setAddWatermark(false)\n .build();\n\n // For Vertex AI use Firebase.ai(backend = GenerativeBackend.vertexAI())\n ImagenModelFutures model = ImagenModelFutures.from(\n FirebaseAI.ai(backend = GenerativeBackend.googleAI()).imagenModel(\n \"imagen-3.0-generate-002\",\n config,\n ImagenSafetySettings.builder()\n .setSafetyFilterLevel(ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE)\n .setPersonFilterLevel(ImagenPersonFilterLevel.BLOCK_ALL)\n .build())\n );\n\nOnce your `ImagenModel` is instantiated, you can generate images by calling\n`generateImages`: \n\n### Kotlin\n\n val imageResponse = model.generateImages(\n prompt = \"An astronaut riding a horse\",\n )\n val image = imageResponse.images.first\n val bitmapImage = image.asBitmap()\n\n### Java\n\n CompletableFuture\u003cGenerateContentResponse\u003e futureResponse =\n model.generateContent(\n Content.newBuilder()\n .addParts(\n Part.newBuilder()\n .setText(\"An astronaut riding a horse\")\n .build())\n .build());\n\n try {\n GenerateContentResponse imageResponse = futureResponse.get();\n List\u003cGeneratedImage\u003e images =\n imageResponse\n .getCandidates(0)\n .getContent()\n .getParts(0)\n .getInlineData()\n .getImagesList();\n\n if (!images.isEmpty()) {\n GeneratedImage image = images.get(0);\n Bitmap bitmapImage = image.asBitmap();\n // Use bitmapImage\n }\n } catch (ExecutionException | InterruptedException e) {\n e.printStackTrace();\n }"]]