Menu
Sites
Language

Code snippet for image rotation

How to rotate image onto 90 degrees and save it into file. Here ad->fileList[ad->curIndex] is some char string with path to file. Privilege http://tizen.org/privilege/mediastorage should be added in manifest.
typedef struct appdata {
//…
    int width;
    int height;
    image_util_rotation_e angle;
    media_packet_h mediaPcktPtr;
} appdata_s;
int finalize_callback(media_packet_h packet, int err, void* userdata)
{
    return MEDIA_PACKET_FINALIZE;
}
Evas_Event_Flags on_click_rotation_start(void *data, void *event_info)
{
    appdata_s *ad = (appdata_s *)data;
    void* src_ptr;
    media_format_h fmt;
    media_packet_h src;
    transformation_h handle;

    image_util_transform_create(&handle);

    unsigned char *img_source = NULL;
    int width = 0, height = 0;
    unsigned int size_decode = 0;

    image_util_decode_jpeg( ad->files[ad->curIndex], (image_util_colorspace_e)IMAGE_UTIL_COLORSPACE_RGB888, &img_source, &width, &height, &size_decode);

    ad->width =width;
    ad->height =height;
    ad->angle = IMAGE_UTIL_ROTATION_90;

    media_format_create(&fmt);
    media_format_set_video_mime(fmt, MEDIA_FORMAT_RGB888);
    media_format_set_video_width(fmt, width);
    media_format_set_video_height(fmt, height);

    media_packet_create_alloc(fmt, finalize_callback, NULL, &src);
    image_util_transform_set_rotation(handle, ad->angle);

    media_packet_get_buffer_data_ptr(src, &src_ptr);
    memcpy(src_ptr, img_source, size_decode);
    free(img_source);
    image_util_transform_run(handle, src , (image_util_transform_completed_cb)completed_rotation_callback, ad);
    ad->mediaPcktPtr = src;
    image_util_transform_destroy(handle);
    return EVAS_EVENT_FLAG_NONE;
}
static void completed_rotation_callback(media_packet_h *dst, int error_code, void *user_data)
{
    appdata_s *ad = (appdata_s *)user_data;
    void * ptr;
    dlog_print(DLOG_INFO,LOG_TAG,"completed_rotation_callback");
    media_packet_get_buffer_data_ptr(*dst, &ptr);

    int w = ad->width;
    int h = ad->height;
    if (ad->angle == IMAGE_UTIL_ROTATION_90  || ad->angle == IMAGE_UTIL_ROTATION_270 )
    {
        w = ad->height;
        h = ad->width;
    }
    image_util_encode_jpeg((unsigned char*)ptr, w, h
                                               , IMAGE_UTIL_COLORSPACE_RGB888, 100, "/opt/usr/media/rotated.jpg");
    media_packet_destroy(*dst);
    media_packet_destroy(ad->mediaPcktPtr);
}

Responses

1 Replies
victory yuvaraju

Hi,

I was added image to button but image size is very small, i need to increase size of image ,Please suggest to me proper solution for it