// Create an array to store local image creative objects.
Creative[] imageCreatives = new ImageCreative[5];
for (int i = 0; i < 5; i++) {
ImageCreative imageCreative = new ImageCreative();
imageCreative.setName("Image creative #" + i);
imageCreative.setAdvertiserId(advertiserId);
imageCreative.setDestinationUrl("http://google.com");
imageCreative.setImageName("image.jpg");
imageCreative.setImageByteArray(
MediaUtils.getAssetDataFromUrl(
"http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg"));
imageCreative.setSize(new Size(300, 250, false));
imageCreatives[i] = imageCreative;
}
// Create the image creatives on the server.
imageCreatives = creativeService.createCreatives(imageCreatives);
if (imageCreatives != null) {
for (Creative creative : imageCreatives) {
// Use instanceof to determine what type of creative was returned.
if (creative instanceof ImageCreative) {
ImageCreative imageCreative = (ImageCreative) creative;
System.out.println("An image creative with ID \"" + imageCreative.getId()
+ "\", name \"" + imageCreative.getName()
+ "\", and size {" + imageCreative.getSize().getWidth()
+ ", " + imageCreative.getSize().getHeight() + "} was created and\n"
+ " can be previewed at: " + imageCreative.getPreviewUrl());
} else {
System.out.println("A creative with ID \"" + creative.getId()
+ "\", name \"" + creative.getName()
+ "\", and type \"" + creative.getCreativeType() + "\" was created.");
}