0

How to fit a big image say (1920 * 1080) into small Graphics 2D context (may be 960 * 540). Which api i should to call before :

context_.ReplaceContents(&image_data);

This image data variable have a size of (1920 * 1040 * 4 (as i am using RGBA format, so 4 bits for each pixel)

I am using google pepper plugin apis for my developement.

Devesh Agrawal
  • 8,982
  • 16
  • 82
  • 131

1 Answers1

0

You're going to need to resize or crop your image. If you want to crop the image, you can use PaintImageData instead of ReplaceContents.

There is no Pepper API to resize the image, so you will need to write this code yourself or use a library. A quick stackoverflow search found this link:

Fastest C/C++ image resizing library

A few of the libraries mentioned here are available in naclports, including OpenCV, ImageMagick and DevIL.

If you're not too concerned about the quality you can just do a simple scaling algorithm yourself. Here is another stackoverflow link that may be helpful:

Image scaling and rotating in C/C++

Community
  • 1
  • 1
binji
  • 1,860
  • 9
  • 9
  • Thanks binji for clarification. I can see one API bool SetScale (float scale); the description they mentioned for that exactly match my requirement. but when i use it, it makes no effect for me. If you dont mind can you please tell how and in which situation this api needs to be used. – Devesh Agrawal Jul 09 '14 at 02:57
  • You're right, SetScale might work for you. It was designed for use with HiDPI devices, but it works for normal screen resolutions as well. To use it, you must call it before you Bind the graphics2d context to the instance (i.e. before the call to BindGraphics). – binji Jul 16 '14 at 17:33