I made an application that stores Item picture (jpeg) on SQL Server DB, I am using pictures shot with my camera (file size ~ 2 M). I am checking if picture.Width > 800 or picture.Height > 600, then I resize the picture to 800x600.
If I export picture from DB, the file size is about 100k, and if I open the same picture in photoshop, the image size is shown 1.37M.
Now my questions are:
First, I want to know the space that this picture takes in my DB.
The reason I'm resizing the picture before storing it in my DB, is that I imagine it taking a huge space in my DB.
Second, How do I resize a picture to keep it's aspect ratio?
The size of the jpg file depends of the widht, height and the color dept. Check this link http://jan.ucc.nau.edu/lrm22/pixels2bytes/calculator.htm to calculate the image size.
to resize the picture size and keep the aspect ratio there is a lot of libraries and framewrok to complete the task. I do not recomend you to implement one unless
you have to (there is a lot of good libraries). check this post Image resizing algorithm.
Its not good idea to store image in DB check Storing Images in DB - Yea or Nay?
Related
I need to generate some large graphs whose width and height can go up to millions of pixels in size. Please note that I do NOT want to scale down the image. Each point must represent one pixel.
Now using the Bitmap and Graphics objects, this is very much possible if I split the image into smaller squares but it is painfully slow.
I already calculate the pixel RGB values so was wondering if there is a way to create a byte array with these values and manually save them as an uncompressed BMP format file instead of dealing with the Bitmap class and the drawing functions of the Graphics class.
I am comfortable with unsafe code if that helps to speed up the process.
If you're displaying graphs, why don't you use a technology like SVG that can be rendered on the fly with very little processing power, yet can scale to near-infinite sizes thanks to vector expansion?
(While there is good question if anything will be able to read such files...)
BMP format is very simple - you can write it directly to disk (I'd recommend avoiding building huge file in memory unless you have other reasons to do so). There is a fixed-size header and then (for 24bpp) sequences of colors aligned on some width. Assuming you can pick width you will not even need to add any padding - just rows of colors for each pixel.
I am working in a project where each user has a big avatar and a thumbnail of this avatar. The avatar is 150x215 and the thumbnail is 50x50. To generate the thumbnail, the user selects a square area inside the avatar and the system crops and resizes the avatar to generate the thumbnail.
Now I need to have a 70x70 thumbnail. I cannot resize the 50x50 thumbnail because it does not look nice. My idea was to create a tool to find the thumbnail inside the avatar and, using the thumbnail location, generate the new 70x70 image. It was working well until I notice that some thumbnails are not only cropped, they are resized. When the image is resized it loses pixels what makes a pixel-by-pixel comparison impossible (so I can't detect the thumbnail location inside the avatar).
Is there any way to identify where the thumbnail is located(even though it is resized)? I am using EMGU to handle the images.
Thanks for any help
[EDIT1]
Seeing your note, if you had the scaling factors applied to the original avatar, then you could create a temp thumbnail that has the same scaling factor applied, then perform a statistical equivalence check of the thumbnail against the already scaled avatar. What this would look like is finding the "difference image" of the thumbnail against the scaled avatar image for each location the thumbnail can possibly lie within the avatar. for each of these "difference images" add all of the pixel based differences into a combined single numeric difference and store that into a 2D array sized to the dimension of x and y locations the thumbnail can possibly be placed within the scaled avatar image (this will be smaller than the total avatar image size, infact it will be width = avatarWidth - thumbWidth and height = avatarHeight - thumbHeight). After you have calculated all of the single difference instances for this 2D array, simply find the min within the array and that is the top-left pixel location within the scaled avatar to use. You will of course have to take the new scaled size of the 50 x 50 thumb into account when grabbing your 70 x 70 from this calculated top-left point.
You dont (by the way) have to store this 2D array of difference values, You could simply hold a min location that is initialized with the value from the first tested location, and only update if the current location is less than the current min. This would avoid the added storage of the array.
[ORIGINAL]
Once the avatar image has been resized, it has also been interpolated, which for all intensive purposes means that the original pixel information has been mathmatically changed irreversibly.
You may have better luck getting into the original thumbnailing code, and changing the thumbnail code to grab the 70 x 70 px sub-image, then create the 50 x 50 by cropping another 10 px from each side!!! This is assuming you still need both the 50 x50 and the 70 x 70 thumbnails.
My application works with large amount of images and I have to store some calculated info about each one. Frequently I need to get image's size for my calculations (sometimes without need to load original image).
What is better: each time to load needed Bitmap and to get its size, or at first get the size and store it in a Size object?
You said yourself "without need to load original image" - so sure get the compiled info for your bitmaps and store them. If you use a DB then you can for example store just your infos and the path to your bitmap. Only load big pictures if you really need them.
My application is used to design airports for a flight simulator. Users can add one or more images as background. The image(s) can be sized accurately and then used as a template to lay down features such as runways, aprons and so on.
I use a third party graphics library (Piccolo) which has an image class (as far as I can see it is a simple wrapper for System.Drawing.Image).
So far I have done little except allow the user to add an image, size it and so on. It will be no surprise that users sometimes complain of poor performance. We tell them not to load large images (up to 100k seem OK) but don't stop them and 100Mb bitmaps have been used with horrible results.
I need to fix this in a couple of ways. First by converting any image they use to an efficient format (size vs definition) and second by ensuring that the loaded image is suitably sized for the dimensions - at the moment I don't do anything specific to deal with the resizing of say a 2000 x 2000 image to fit a 500 x 500 area of the display.
The default 1:1 display of the application represents 1m per pixel. Once the user has resized the image to fit accurately would I be right in thinking that the best resoultion for the image would be to resample it to that size? I am aware that if the user zooms in way past 1:1 which they will probably do then the clarity of the image will fall.
My ignorance of handling images is complete. I have looked at some image manipulation libraries (ImageMagick and the free version of dotIamge) first for converting the input image to a standard one and second for resizing -resampling. The truth is that they do far more than I need.
Any pointer much appreciated.
Yes, resampling so that the bitmap doesn't constantly have to be rescaled for every paint should make a big difference. The default Graphics.InterpolationMode makes pretty images but is not cheap.
Another biggie is the pixel format of the bitmap. Format32bppPArgb is 10 times faster than any of the others on most video adapters.
private static Bitmap Resample(Image img, Size size) {
var bmp = new Bitmap(size.Width, size.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
using (var gr = Graphics.FromImage(bmp)) {
gr.DrawImage(img, new Rectangle(Point.Empty, size));
}
return bmp;
}
I'm tying to figure out away to split/slice a large image >5000x5000 PX into small images using a grid system where each slice have its unique ID then save images in database
Each slice should have its location (width,height + X,Y) on the original image (maybe in array) so later on i can ReBuild the original image using these slices
http://i.stack.imgur.com/PKYem.jpg
You can use Bitmap.Clone Method (Rectangle, PixelFormat) to slice the image rectangle by rectangle.