Extract pixels buffer from Image Gdi+ - graphics

I would like to extract pixel buffer from Gdiplus::Image
Here is my code :
Gdiplus::Bitmap bitmap(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), BPP4 * GetSystemMetrics(SM_CXSCREEN), PixelFormat32bppARGB, data);
Gdiplus::Image *pThumbnail = bitmap.GetThumbnailImage(mWidthResolutionSelected, mHeightResolutionSelected, NULL, NULL);
How to get pixel buffer after the scale with GetThumbnailImage from pThumbnail ?
Thanks

You cast pThumbnail to a Bitmap* and then you use the LockBits method to get a BitmapData object, which contains the Scan0 field, which is a pointer to the pixel data. Don't forget to call UnlockBits when you're done.

Related

Fabric.js - Applying pixelate filter to resized image

Currently, the way Fabric.js works as far as I can tell is that its filters are applied to the original image, regardless of what it looks like on the canvas. Is there a way, by either "branching" the pixelate filter or through some other method, to have the filter be applied to the image as shown on the canvas, resized and oriented? How would I do this?
An example: I have an image within the canvas that can be resized. The user resizes it. I want to apply a filter to the resized version of that image, not the original uploaded image.
Thank you!
Okay, I think I see what you're trying to do. Assuming you're using the pixelate filter and want to get a consistent blocksize regardless of how big the image is on the canvas, you could simply set the filter's block size value as a function of the image's scale. By putting the blocksize calculation in an object:modified event it will recalculate each time an image is modified.
canvas.on('object:modified', function(e) {
var obj = e.target;
if(obj.type == "image") {
var blocksize = 16 / obj.scaleX;
obj.filters[0].blocksize = blocksize;
obj.applyFilters();
}
});

How to read jpg using FreeImage

I am new to FreeImage. I just want to read an JPEG image and display it in my MFC dialog. How do I do that? I try that using ImageStone by doing:
img.Load(blob.data, size, IMG_JPG);
img.Draw(hdc, DC);
Now, how do I do the same thing using FreeImage?
I tried and it worked exactly the way you described.... I used SHCreateMemStream and fed the stream to the overloaded LOAD method of CImage. Everything worked perfectly.
Thank you so much,
Makoto
CImage im;
IStream* is = SHCreateMemStream(Blob.pData, nSize);
HRESULT hr = im.Load(is);
RECT rect = { 0, 0, 500, 500 };
BOOL b = im.Draw(hdc, rect);

Get pixel data from Graphics object in Codename One

I'm trying to implement the Gaussian blur filter on Graphics object, but I can't find function for get pixel information or transform Graphics object to byte array (with RGB data).
That isn't supported since hardware accelerated surfaces might not provide that information.
However, you can do something else. Just paint the current form onto a mutable image and then just get the RGB of the mutable image which you can then use to create a new Image from an RGB e.g. something close to this:
Display d = Display.getInstance();
Image img = Image.createImage(d.getDisplayWidth(), d.getDisplayHeight());
Graphics g = img.getGraphics();
d.getCurrent().paintBackgrounds(g);
d.getCurrent().paintComponent(g, false);
int[] bufferArray = img.getRGB();
// blur...
Image blurredImage = Image.createImage(bufferArray, img.getWidth(), img.getHeight());

Android: How to get bitmap from HashMap object?

I have a HashMap in which I stored images with Bitmap format. Now the problem is how do I get those images again?
In details,
Here in this hasmap, I stored my Bitmap image as an object.
ArrayList<HashMap<String,Object>> mImgList = new ArrayList<HashMap<String,Object>>();
Bitmap img = imgLoader.decodeSampledBitmapFactoryFromUrl(x,x,x,x);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(TAG_IMG, img);
map.put(TAG_NAME, name);
map.put(TAG_ID, cont_id);
mImgList.add(map);
I use this hashmap in the listview to diplay img and text, everything's fine.
But now I need to display some of those images in a ImageView, but I don't know how to get the image as those Bitmap in the HashMap is becoming an object.
I tried to use:
Bitmap bmp = mImgList.get(x).get(TAG_IMG);
but what i got is actualy an object not a bitmap. so how should i get my bitmap? or are there any other way I can display this picture on the alertdialog? thanks!
Turns out no one answered my question...But I end up converting bitmap into drawable so that I can save them into hashmap and get them when i want.
Bitmap bitmap = (Bitmap) mMap.get("bitmap_key_001");

SKIA - Inaccurate value returned by measureText()

I have a problem measuring text using skia measureText() function.
The value returned is inaccurate.
SkPaint *skPaint = new SkPaint();
SkTypeface* myFont = SkTypeface::CreateFromName("Impact", SkTypeface::kNormal);
skPaint->setTypeface(myFont);
skPaint->setAntiAlias(true);
skPaint->setTextAlign(SkPaint::kLeft_Align);
skPaint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
skPaint->setTextSize(SkIntToScalar(120));
skPaint->setColor(0xff000001);
canvas->drawText(text, length, SkIntToScalar(x) , SkIntToScalar(y) , *skPaint);
SkScalar width = skPaint->measureText(text, length);
The width returned by measureText() is 451.
I checked the generated bitmap text via a photo editor app, the actual width is only 438.
Any thoughts on getting the accurate width of text in SKIA?
Thank you!
I believe what you are trying to match will come from "bounds"
SkRect bounds;
SkScalar textWidth = paint.measureText("some", 4, &bounds);
which is a minimum rectangle to fit a given text, whereas textWidth is slightly larger than that.
I faced this issue too. Dont know why exactly it happens, maybe because of kerning differences, but i came to this:
SizeF RenderTextAndroid::GetStringSizeF() {
UpdateFont();
const base::string16& text = GetLayoutText();
std::vector<SkScalar> widths(text.length());
paint_.getTextWidths(text.c_str(), GetStrByteLen(text), &widths[0], NULL);
return SizeF(std::accumulate(widths.begin(), widths.end(), 0),
font_metrics_.fBottom - font_metrics_.fTop);
}
Where UpdateFont just sets new parameters to SkPaint

Resources