hBitmap To Image Widget #385
-
Hey! Can someone tell me how to display a screenshot immediately in flutter.
But I can't display it immediately in the widget. P.s. Yes, I need a 300x300 square |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I used the original screenshot example and replaced the section where it saves to a file with the below. var b = BytesBuilder();
b.add(Pointer<Uint8>.fromAddress(bitmapFileHeader.address)
.asTypedList(sizeOf<BITMAPFILEHEADER>()));
b.add(Pointer<Uint8>.fromAddress(bitmapInfoHeader.address)
.asTypedList(sizeOf<BITMAPINFOHEADER>()));
b.add(lpBitmap.asTypedList(dwBmpSize));
return b.toBytes(); This gives you a bitmap as an array of bytes, which you can use with |
Beta Was this translation helpful? Give feedback.
-
Any helpful info with region capture? I write some code but fail to work. static Uint8List captureRegion(int x, int y, int w, int h) {
int hScreen = GetDC(NULL);
int hDC = CreateCompatibleDC(hScreen);
int hBitmap = CreateCompatibleBitmap(hScreen, w, h);
try {
int oldObj = SelectObject(hDC, hBitmap);
BitBlt(hDC, 0, 0, w, h, hScreen, x, y, SRCCOPY);
var bmp = calloc<BITMAP>();
GetObject(hBitmap, sizeOf<BITMAP>(), bmp);
final bitmapFileHeader = calloc<BITMAPFILEHEADER>();
final bitmapInfoHeader = calloc<BITMAPINFOHEADER>()
..ref.biSize = sizeOf<BITMAPINFOHEADER>()
..ref.biWidth = bmp.ref.bmWidth
..ref.biHeight = bmp.ref.bmHeight
..ref.biPlanes = 1
..ref.biBitCount = 32
..ref.biCompression = BI_RGB;
final dwBmpSize =
((bmp.ref.bmWidth * bitmapInfoHeader.ref.biBitCount + 31) /
32 *
4 *
bmp.ref.bmHeight)
.toInt();
var lpBitmap = calloc<Uint8>(dwBmpSize);
GetDIBits(hDC, hBitmap, 0, bmp.ref.bmHeight, lpBitmap,
bitmapInfoHeader.cast(), DIB_RGB_COLORS);
var b = BytesBuilder();
b.add(Pointer<Uint8>.fromAddress(bitmapFileHeader.address)
.asTypedList(sizeOf<BITMAPFILEHEADER>()));
b.add(Pointer<Uint8>.fromAddress(bitmapInfoHeader.address)
.asTypedList(sizeOf<BITMAPINFOHEADER>()));
b.add(lpBitmap.asTypedList(dwBmpSize));
free(lpBitmap);
free(bitmapInfoHeader);
free(bitmapFileHeader);
free(bmp);
return b.toBytes();
// GetClipboardData(CF_BITMAP);
} finally {
DeleteObject(hBitmap);
DeleteDC(hDC);
ReleaseDC(NULL, hScreen);
CloseClipboard();
}
|
Beta Was this translation helpful? Give feedback.
I used the original screenshot example and replaced the section where it saves to a file with the below.
This gives you a bitmap as an array of bytes, which you can use with
Image.memory(bytes)
in flutter.