Change color type of bitmap in SkiaSharp? - skiasharp

I have a bunch of gifs I want to create thumbnails for using SkiaSharp. But SKBitmap.Resize method returns null when having a source bitmap with color type other than 32-bit (as it seems). But how do I change the source bitmap to 32-bit colors? (from Index8)

Related

Actionscript 3 - Bitmaps and Symbols

I am working on flash professional cs5.5 and actionscript 3. I need to use symbols of customized sizes to test the hitTestOjbect() function. However, when i convert the bitmap to a symbol, by default it goes into a rectangular size and the empty space all around is also detected as part of the symbol.
Is there any way to keep the size of the symbol customized ?
That is the nature of a bitmap. Technically, bitmaps are always rectangular. Transparent areas are just fills with alpha-0. When you convert a bitmap to a symbol, the bitmap still exists, just inside the context of the symbol.
One of the fastest ways to fix this is to use a mask inside your MovieClip. Create a plain drawing object in the exact shape of the hit area you want. Then, place that on your timeline on it's own layer. Right-click the layer with the mask, click "Mask", and then drag the bitmap's layer under the mask one. Lock both layers, and exit symbol editing.
Now your hit area will be limited to only the masked area.
EDIT: I appear to be mistaken - hitTestArea is always rectangular. See the top answer to hitTestObject Collision Not Registering Correctly.

Error #2077: This filter operation cannot be performed with the specified input parameters

Error #2077: This filter operation cannot be performed with the specified input parameters.
at flash.display::BitmapData/applyFilter()
I got this error message trying to apply a BitmapFilter (specifically an inner DropShadowFilter) to a BitmapData via .applyFilter
I've never seen this message before and Googling did not immediately answer the question, and I saw someone confounded as to why it applied to JPEG and not PNG images. So hopefully this question will help someone else. I'll include my simple solution below.
Reading the BitmapData.applyFilter documentation, it's fairly obvious what the problem is. I tried to apply a DropShadowFilter to a BitmapData without transparency (aka, no alpha channel, only 24 bits per pixel.) The docs state which filters require transparency (replicated here for convenience):
Each type of filter has certain requirements, as follows:
BlurFilter — This filter can use source and destination images that are either opaque or transparent. If the formats of the images do not match, the copy of the source image that is made during the filtering matches the format of the destination image.
BevelFilter, DropShadowFilter, GlowFilter, ChromeFilter — The destination image of these filters must be a transparent image. Calling DropShadowFilter or GlowFilter creates an image that contains the alpha channel data of the drop shadow or glow. It does not create the drop shadow onto the destination image. If you use any of these filters with an opaque destination image, an exception is thrown.
ConvolutionFilter — This filter can use source and destination images that are either opaque or transparent.
ColorMatrixFilter — This filter can use source and destination images that are either opaque or transparent.
DisplacementMapFilter — This filter can use source and destination images that are either opaque or transparent, but the source and destination image formats must be the same.
Creating a BitmapData with transparency is easy - it's the 3rd parameter to the constructor:
// args are: width, height, is_transparent, default_color
var bd:BitmapData = new BitmapData(1024, 768, true, 0xff000000);
Note that when you create a transparent BitmapData, you must specify a 32-bit integer for the default color (the 4th parameter). If you merely specify 0xffffff (24-bit white), you'll get a blank image as the alpha value (the highest 8 bits) are 0.

Can GIF store grayscale images without a palette?

Does GIF specify some form of grayscale format that would not require a palette? Normally, when you have a palette, then you can emulate grayscale by setting all palette entries to gray levels. But with other formats (e.g. TIFF) the grayscale palette is implicit and doesn't need to be saved in the file at all; it is assumed that a pixel value of 0 is black and 255 is white.
So is it possible to create such a GIF? I'm using the giflib C library (5.0.5), if that matters.
I forgot about this question. Meanwhile I would out the answer. The GIF format requires a palette. No way around that.

AS3 cacheAsBitmap questions?

I'm a bit confused. If I import a png picture, drag it onto my stage, and right click > convert to bitmap. Is that the same thing is if I have a vector created in code, and then apple cacheAsBitmap = true?
A PNG picture is a raster object, and it has a parent class of Bitmap already. You might, however, encapsulate that Bitmap into a drawn rectangle (effectively making a rectangle with bitmap fill, that is actually a vector object), and then convert to bitmap, applying cacheAsBitmap = true to the vector object made of the raster object. I don't understand why do you want double transformation raster->vector->raster in the first place. Probably Flash isn't so stupid if you just drag a library asset made out of a PNG to the stage, it'll make you a Bitmap based object instead, and "convert to bitmap" won't do a thing.

BitmapData.draw with different shape

is it possible to change the Rectangle I use as fifth parameter of draw BitmapData class?
bitmapData.draw(image,null,null,null,rect,false);
I'm trying to draw and save a different shape (with the shape of a particular MovieClip).
If you look at the definition for the BitmapData's copyPixels method (adobe documentation), you'll see:
"If you include the alphaBitmap and alphaPoint parameters, you can use
a secondary image as an alpha source for the source image. If the
source image has alpha data, both sets of alpha data are used to
composite pixels from the source image to the destination image. The
alphaPoint parameter is the point in the alpha image that corresponds
to the upper-left corner of the source rectangle. Any pixels outside
the intersection of the source image and alpha image are not copied to
the destination image."
You can probably get this to do what you want.