image manipulation in skia

804 views
Skip to first unread message

swagat mishra

unread,
Jul 4, 2012, 5:15:18 PM7/4/12
to skia-d...@googlegroups.com
hi,
i am new to skia and have it set up on my windows machine. i need to do image rendering using skia for which as a starter, i need to read the various image properties(like Pixelformat,width and height)  of a JPG image using SKIA.i need to do this to get started on SKIA , so it would be helpful if someone could help me with some documentation tutorials or sample code. 
Thanks,
swagat

Chandramouli Sanchi

unread,
Jul 5, 2012, 12:22:47 AM7/5/12
to skia-d...@googlegroups.com
Hi,
 
Plz check below sample code
 
#define WIDTH 800
#define HEIGHT 800
unsigned int *pBuffer;
SkBitmap bitmap;
SkCanvas canvas;
 
int main()
{
// pBuffer = (unsigned int *) malloc (sizeof(unsigned int) * WIDTH * HEIGHT);

 bitmap.setConfig(SkBitmap::kARGB_8888_Config, WIDTH, HEIGHT);
// bitmap.setPixels(pBuffer);
 bitmap.allocPixels();
 bitmap.eraseColor(SK_ColorWHITE);

 canvas.setBitmapDevice(bitmap);
 
 DrawImage();
}
 
_____________________
void DrawImage()
{
 SkBitmap Bitmap;
 SkPaint paint;
 SkImageDecoder::DecodeFile("E:\\DSC00013.bmp", &Bitmap, SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode);
 paint.setAntiAlias(true);
 paint.setDither(true);
 paint.setFilterBitmap(true);
 canvas.drawBitmap(Bitmap, 0, 0, &paint);
 
}
 
(or)
_____
void DrawImage()
{
 SkBitmap Bitmap;
 SkPaint paint;
 unsigned char *data;
 int w, h;
//NOTE::ALLOCATE BUFFER DATA IF U KNOW WIDTH AND HEIGHT
 data = (unsigned char *) malloc (sizeof(unsigned char) * 200 * 200 * 4);
 //read_bmp("E:\\DSC00013.bmp", data, &w, &h);
 //read_bmp("E:\\test.bmp", data, &w, &h);
 Bitmap.setConfig(SkBitmap::kARGB_8888_Config, w,h, w * 4);
 Bitmap.setPixels(data);
 
 paint.setAntiAlias(true);
 paint.setDither(true);
 paint.setFilterBitmap(true);
 canvas.drawBitmap(Bitmap, 500, 10, &paint);
 
 free(data);
}
__________

Regards,
Chandramouli
 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/skia-discuss/-/7TqL7nir9lsJ.
To post to this group, send email to skia-d...@googlegroups.com.
To unsubscribe from this group, send email to skia-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/skia-discuss?hl=en.

swagat mishra

unread,
Jul 5, 2012, 2:12:44 AM7/5/12
to skia-d...@googlegroups.com, cm.s...@gmail.com
hi,
Thanks for your answer.
However , i do not need to decode the image yet. i need to just read the image attributes of the image. Are there any such functions exposed by skia?

刘思翔

unread,
Jul 5, 2012, 2:16:34 AM7/5/12
to skia-d...@googlegroups.com
Do you just want to know the width and height of the image?
you can specifiy the param to bounders, not pixel.

To unsubscribe from this group, send email to skia-discuss+unsub...@googlegroups.com.

swagat mishra

unread,
Jul 5, 2012, 2:19:36 AM7/5/12
to skia-d...@googlegroups.com
i already have an image file (1.jpg). i need to read the image (i guess i can use skstream for that) and then read the image attributes like width and height and pixelformat for it.

swagat mishra

unread,
Jul 5, 2012, 2:21:48 AM7/5/12
to skia-d...@googlegroups.com
also at the time of reading the image, i wont be knowing whether it is a jpg or some other file format. So i have to find the format as well. Any Skia API function for that?

刘思翔

unread,
Jul 5, 2012, 2:24:48 AM7/5/12
to skia-d...@googlegroups.com
use the interface:
SkImageDecoder::DecodeFile(
      const char file[],
      SkBitmap * bitmap,
      SkBitmap::Config prefConfig,
      Mode,
      Format* format = NULL
      );
enjoy it!

swagat mishra

unread,
Jul 5, 2012, 2:27:16 AM7/5/12
to skia-d...@googlegroups.com
Will this work for any format of image supported by skia? 

刘思翔

unread,
Jul 5, 2012, 2:34:59 AM7/5/12
to skia-d...@googlegroups.com
dear,
      image formats skia suported is determine on the implements of skia decoders. There are quite different for each platform. for windows, the implements of decoders are based on COM, so, can think that is available for all format, such as jpeg, png, git and so on.

swagat mishra

unread,
Jul 5, 2012, 2:38:21 AM7/5/12
to skia-d...@googlegroups.com
so just to summarise ( so that i dnt misunderstand anything):
1) i make an skstream to the image file( 1.jpg)
2) use the interface skimagedecoder::decodefile
3) and then use the format pointer to get all image attributes?

刘思翔

unread,
Jul 5, 2012, 2:40:01 AM7/5/12
to skia-d...@googlegroups.com
yes, all right!

Chandramouli Sanchi

unread,
Jul 5, 2012, 2:40:52 AM7/5/12
to skia-d...@googlegroups.com
If you specify "SkImageDecoder::kDecodeBounds_Mode" decodes only bounds not actual pixels.


 
On Thu, Jul 5, 2012 at 12:04 PM, 刘思翔 <liusix...@126.com> wrote:

Chandramouli Sanchi

unread,
Jul 5, 2012, 2:42:51 AM7/5/12
to skia-d...@googlegroups.com
Use SkImageDecoder::DecodeStream if u have stream.

swagat mishra

unread,
Jul 6, 2012, 10:02:11 AM7/6/12
to skia-d...@googlegroups.com
Hi,
i am able to get the image height and width from the SkBitmap after decoding it. However i also need to get the image attributes like
a.PixelFormat
b.Resolution – xDpi, yDpi
c.FrameCount
d.ContainerFormat(programmatically determine if the image is BMP, or PNG, etc. 

Chandramouli Sanchi

unread,
Jul 9, 2012, 12:42:34 AM7/9/12
to skia-d...@googlegroups.com
Hi,
 
Plz check my comments inlined.
 
a.PixelFormat
[Chandra] use "bitmap.getConfig()" to know the pixel format.
 
b.Resolution – xDpi, yDpi
[Chandra] From the skia point of view only "bitmap.width() and bitmap.height()" gives with and height of the bitmap but its upto the device manager to map
"Device pixels per inch"
 
c.FrameCount
[Chandra] With the bitmap you always get FrameCount as 1. But if you create SkMovie class for animated giff images then you may get number of frames.
 
d.ContainerFormat(programmatically determine if the image is BMP, or PNG, etc. 
[Chandra] You need to compare first 4 bytes with ur image data to know the image format.For example
               static unsigned char bmpheader[] = {0x42, 0x4D };
                if (strcmp(imagedata, bmpheader, 2) == 0)
                       print "BMP"
              Plz refer all the image formats header information for more details.
 
 
Regards,
Chandra

Reply all
Reply to author
Forward
0 new messages