How can i get the GtkImage width and height after reading from a file.
If you want the size of the actual image, you need to go through the GdkPixbuf API:
const GdkPixbuf *pb = gtk_image_get_pixbuf(GTK_IMAGE(image));
printf("image is %ux%u pixels\n", gdk_pixbuf_get_width(pb),
gdk_pixbuf_get_height(pb));
Note that this size is not the same as the size of the GtkImage widget that shows the image, since the widget can be given a different size by GTK+'s layout engine.
GtkImage is a subclass of GtkWidget. You should be able to use gtk_widget_get_allocation, and use the height and width fields of the GtkAllocation * that it returns.
Related
I'd like to list some components in a row and when a component reaches the end of the page it should just move to the next row. In this way I expect the page to be adjusted dynamically to the size of the screen. I don’t have a code example because it’s a theoretical question.
You can use the screen width/height to calculate the size of the row widgets.
To get the screen size do the following:
final height = MediaQuery.of(context).size.height;
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height; final width = MediaQuery.of(context).size.width;
// or you can use screen util package it make your screen responsive
and make your code inside SizedBox
it will work
like this :
SizedBox( height: 100, width: width * 0.85 // this mean width is 85% of screen width// child: //your code ),
The obvious answer is Wrap. Give it some children, and it lays them out by default start to end horizontally, and when the next child doesn't fit, it starts a second line.
You don't even need to put it in a row, but you can certainly use it as part of a row or part of a column.
The application looks good on a Pixel 4 XL (resolution of 1440 x 3040) but is overflowing on a Samsung A5 (720 x 1280).
I expected the components to be scaled based on the resolution/ppi, but it seems that I misunderstood.
So how can I fix this ?
Any help is greatly appreciated.
Thanks.
One way of achieving a great looking UI on different screen sizes is to size your widgets relatively to the screen size, and not with pixel amounts, since when the screen's width or height is smaller or bigger, and the widgets are the same size, the UI will either go out of bounds or you will have empty spaces in your UI.
how to achieve that:
in your build function you can store the screen size in a variable:
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
...
then in your widgets that you are returning in the build function, for example a container, change the pixel values to values relative to the screen size:
instead of
return Container(width: 50, height: 70);
write stuff like:
return Container(width: screenSize.width * 0.1,
height: screenSize.height * 0.12);
Image image = Image.getInstance(picture.jpg);
image.scaleAbsolute(800f, 600f); // i just set the image by a certain size
document.add(image);
I want it fits to the whole page of pdf. What method can i use? i need help, thank you
I was looking for a solution, thank your for your question and the comment of #mkl.
here is the sample code, I hope this might help someone.
int width =x; int height = y;
//define these two based on your required width and height ratio of image
document.setPageSize(new Rectangle(width, height));
document.setMargins(0,0,0,0);
img.scaleToFit(height, width);
I have an image in size of 150 pixel in height and 188 pixel in width. I'm going to calculate HOG on this image. As this descriptor needs the size of detector window(image) to be 64x128, Should I resize my image to 64x128 and then use this descriptor? like this :
Image<Gray, Byte> GrayFrame = new Image<Gray, Byte>(_TrainImg.Size);
GrayFrame = GrayFrame.Resize(64, 128, INTER.CV_INTER_LINEAR);
I concern resizing may change the original gradients orientation depending on how it is resized since we are ignoring the aspect ratio of the image?
By the way, The image is croped and I can't crop it anymore. It means this is the size of image after cropping and this is my final bounding box.
Unfortunately the openCV HoGDescriptor documentation is missing.
In openCV you can change the values for detection window, cell size, blockStride and block size.
cv::HOGDescriptor hogDesc;
hogDesc.blockSize = cv::Size(2*binSize, 2*binSize);
hogDesc.blockStride = cv::Size(binSize, binSize);
hogDesc.cellSize = cv::Size(binSize, binSize);
hogDesc.winSize = cv::Size(imgWidth, imgHeight);
Then extract features using
std::vector<float> descriptors;
std::vector<cv::Point> locations;
hogDesc.compute(img, descriptors, cv::Size(0,0), cv::Size(0,0), locations);
Note:
I guess, that the winSize has to be divisible by the blockSize and the blockSize by the cellSize.
The size of the features is dependent on all these variables, so ensure to use images of same size and do not change the settings to not run into trouble.
Actually, i am shrinking high qualitiy images. I need to have one parameter (width or heigth) fixed and the other is flexible but with a defined minimum.
I want to keep the widht/height - ratio of the image.
Example:
I have an image (width x heigth) = 2000px x 3000px and i want it to shrink to a width of 968px and a minimum height of 640px while keeping the widht/height - ratio of the image.
Using the imagemagick Perl API, what do i need to issue to shrink such an image?
So far i have used this, but the results were only some white images:
my $image = Image->new();
$image->Read('my_2000x3000_image.jpg');
$image = $image->[0];
$image->Resize('geometry' => '968' . 'x' . '>');
$image->Write('image_968_min_640.jpg');
What you need is Image::Magick and the Scale method, which takes a maximum width and height
The following creates a thumbnail from an existing image:
# Thumbnail Dimensions
my ($max_height, $max_width) = (60,60);
my $thumbImage = new Image::Magick;
$thumbImage->Read($oldfile);
$thumbImage->Scale(geometry => qq{${max_height}x${max_width}});
$thumbImage->Write($newfile);