C++ Builder FMX StretchDraw a bitmap to change the size - c++

I notice that in Firemonkey there is no equivalent of StretchDraw for changing the size of a bitmap that I have in memory.
I need to increase the size of a bitmap in memory before displaying it in a TImage Control. I want the size of the bitmap in memory to match that of a TImage Control before displaying it. The image bitmap is then sent off to a database blob field. When I recall the bitmap from the database, it is the original size and not the stretched size that I need.
Tried using Wrapmode and that works great for displaying and stretching the bitmaps in a TImage but It doesn't save the bitmap as stretched.
Any ideas how to do this in C++ Builder?

Related

How to create and edit a bitmap

I'm trying to create a bitmap that I can change the pixels of and then update the window with that bitmap. I've tried to research a way to just create a bitmap, but that was to no avail.
I need to know how to create a blank bitmap, then change its pixels using x and y coordinates and a color, and then how to draw it to the window. I don't need to save it to the computer and I don't want to convert an existing image into a bitmap.
I'm on windows and using Visual Studio with C++
Just to specify, I need to know the syntax for creating a blank bitmap with a certain width and height, and also what function I need to use to change the pixels' colors, and then how to draw a bitmap to the window. Thank you.
There is a free library ImgSource that you can use which has a huge amount of functionality for images.
http://www.smalleranimals.com/isource.htm
It is available in MSDN, but using a library like ImgSource may be to your advantage.
It provides simple methods for rendering your image onto a device context. And there is a good support forum.

What's the best way to store, strech and display a bitmap using GDI?

I'm not exactly a windows programming expert ;) so please excuse me if this question is trivial.
I have a window on which I want to display a bitmap. The bitmap can be either stretched to span over the whole area or it will be displayed with original aspect ratio and empty space will be filled with a solid brush.
I load the bitmap with LoadImage and display it using BitBlt. I do it on WM_ERASEBKGND, I use the DC from wparam which is a mem DC.
I was thinking of using StretchBlt instead of BitBlt when the bitmap needs to be stretched.
So my questions are:
is it okay to store a bitmap as HBITMAP or should I use DIBSection? Which one is better performance-wise, what's the memory footprint of both solutions?
should I always stretch the bitmap when drawing to a DC on WM_ERASEBKGND, or should I create a compatible DC (or bitmap) with a precomputed stretched bitmap and then just BitBlt it to the target DC?
if I create a precomputed bitmap, should I immediately unload the original bitmap to save on memory?
should I use BitBlt/StretchBlt or CopyImage?
I read that I can also use LoadImage with desired width and height parameter, so that the loaded image is already stretched, is this solution better?
I'd be really grateful for some code examples.
Edit:
GDI+ solutions are welcome too. I'm interested in the best, easiest and best-performing solution for this problem.

Convert single font character into bitmap pixel array in c++

I have a problem converting a character into a bitmap pixel array.
I work with Windows CE 6 and I have written an application in C++ to manage an OLED by serial interface.
To display the image on OLED I use the bitmap format, then if I want to display a text on OLED I have to convert the character to a bitmap array first, but I don't know how take a single character from a Windows CE font and convert it into a bitmap pixel array (bytes) to send it out via the serial interface.
Have you got an idea (standard functions, custom functions etc) how to solve this problem?
CreateDC to create a device context.
CreateCompatibleBitmap to create a bitmap of the right size.
SelectObject to select the bitmap into the DC.
CreateFontIndirect to create font.
SelectObject to select the font into the DC.
DrawText to draw the character on the DC.
SelectObject to select the previously selected bitmap back into the DC.
SelectObject to select the previously selected font back into the DC.
DeleteObject to delete the created font.
DeleteDC to delete the DC.
You now have a bitmap with the letter.

GDI - How to create and fill bitmap?

Someone can give me short explanation how to create bitmap runtime using GDI/GDI+ and to fill it with color ?
Thanks in advance.
CreateBitmap, CreateCompatibleBitmap or CreateDIBSection (in case you want access to raw underlying data bits)
CreateCompatibleDC
SelectObject the bitmap into created device context
FillRect or friends on the device context, and the painting takes place on your selected bitmap (there are options there: standard brushes for black and white, having RGB on hands instead of creating a brush you can do SetBkColor + ExtTextOut with an empty string and ETO_OPAQUE and the rectangle will be filled)
SelectObject back
The bitmap remains to hold the painting
Release the resources
Still it has something to do with "entire screen" in the title, and you need explain what you want there.
Query screen size
Create your drawable (or just manipulate the graphics object in your paint handler)
Fill it with color
:)

MFC image from array

What is the fastest/easiest way to convert an array (of double) into a MFC-Bitmap to be displayed in a Picture Control?
I would start with a CMemDC, where you can set every pixel by CDC::SetPixel(), and then BitBlt it over to a real CDC.
If you want a real bitmap, look here: Creating HBITMAP from memory buffer