I'm building a program in Mathematica that generates very simple GIFS that flip between single color squares. It is designed so that the image data is uncompressed, and does not use the LZW compression that most animated GIFs use. I've come across examples of uncompressed GIFs that are not animated, which are just single images, and I've come across very simple animated gifs that change color but they do use LZW. I haven't yet found an example of uncompressed and animated, and that's what I'm trying to do.
So far my program is successful at creating single frame gifs, as well as animated gifs with multiple frames but the animated gifs always come out the same color for each frame, or just some pixels change color, not the whole frame. I am trying to create animated gifs that flips from, for example, a Red Square to a Black Square, on loop.
Below are the block-by-block bytes of a GIF that my program created. I expected this is GIF to be a 2pixel by 2pixel square where the first frame is Red and then second frame is Black. Instead I got two frames of Red.
Header: 47,49,46,38,39,61
Logical Screen Descriptor: 02,00,02,00,f0,00,00
Global Color Table: ff,00,00,00,00,00
Application Extension Block: 21,ff,0b,4e,45,54,53,43,41,50,45,32, 2e,30,03,01,00,00,00
Graphic Extension Control: 21,f9,04,00,88,13,00,00
ImageDescriptor:2c,00,00,00,00,02,00,02,00,00
ImageData Block: 01,03,02,01,01,03,02,01,01,00,
Graphic Extension Control: 21,f9,04,00,88,13,00,00
ImageDescriptor:2c,00,00,00,00,02,00,02,00,00,
ImageData Block:01,03,02,01,01,03,02,01,01,00
Comment Extension: 21,fe,00,00
Trailer: 3B
If you'd like to look at these bytes in a hexeditor, here is the unbroken string of bytes:
47,49,46,38,39,61,02,00,02,00,f0,00,00,ff,00,00,00,00,00,21,ff,0b,4e,45,54,53,43,41,50,45,32,2e,30,03,01,00,00,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,f9,04,00,88,13,00,00,2c,00,00,00,00,02,00,02,00,00,01,03,02,01,01,03,02,01,01,00,21,fe,00,00,3B
My current thinking on what's the problem(s): Is there something wrong the LZW Minimum size (the first byte of the Image Data Block) or with the Clear Code (the third byte of the Image Data Block), because I've found that when I change them to a different value, it can sometimes make a single or double black pixel appear along with a 1-2 red pixels, but I can't figure out a pattern to the bug.
I also wonder if the background color being set to red is giving me a misleading understanding of the bug – are maybe no or very few pixels actually being drawn, but I can't tell because of the background color is the same as the as pixel color?
Here is the program I'm working on in Mathematica – It is partially commented, but I have not completed the comments yet:
https://www.wolframcloud.com/obj/8b483039-494b-476f-844d-a0f39d1d663b
And finally, these are the best resources I've come across that I have been basing my program off of are:
GifLib – What's in a Gif http://giflib.sourceforge.net/whatsinagif/index.html
Gif File Spec
https://www.w3.org/Graphics/GIF/spec-gif89a.txt
Wikipedia
https://en.wikipedia.org/wiki/GIF
I am using xcode with Swift to develop a very simple application that should only run on iphone7. I have a bunch of UIImages and UIButtons with images in my application and I have received a bunch of PNGs to use in the application.
They are named more or less image1.png, image2.png and so on.
If I check the dimension of the PNGs, they look right to me.
For example one background image has the following dimensions: 750 x 1335.
Once I add this PNG to my application, and add it to the story board, the image looks huge.
I need to manually enter the following dimensions 350 x 887 (which is half the size) in order to get the image to fit the size of the phone on the screen.
I have no idea what is going on here! It is something I am doing wrong or it there something wrong with the exported PNGs?
I think you content mode is not right. This is how to fix it:
Click to your UIImageView
Look at the right hand side and choose View -> Content Mode to Aspect Fit
This is the document about content mode of a Image View
https://useyourloaf.com/blog/stretching-redrawing-and-positioning-with-contentmode/
I hope it can help you
iPhone's physical screen resolution is rarely referenced as is, instead it is calculated in points. On the early iPhones 1 point was actually 1 pixel. On modern iPhones 1 point is actually representing 2x2 pixels, or sometimes 3x3 pixels (for Plus models). To make it all work, all the graphics for UI elements (buttons and the like) are provided in two or three resolutions:
for the case where 1point = 1pixel
in such case the image name is not postfixed with anything (image1.png)
for the case where 1point = 2x2pixels
in this case the image name is postfixed with #2x (image1#2x.png)
for the case where 1point = 3x3pixels
in this case the image name is postfixed with #3x (image1#3x.png)
You have two ways of managing this.
First goes like this:
Rename all of your images, so that they all have #2x.png at the end. Like this:
image1.png becomes image1#2x.png
image2.png becomes image2#2x.png
Drag all those images to your Assets.xcassets folder in XCode:
Now you can assign the images to buttons, backgrounds, and pretty much anything else by calling its name (omitting the #2x at the end), like this: image1, image2, etc. The resolution will fit now.
You can also choose the images in drop-down lists in your Storyboard to apply them to different elements (like said buttons).
Second way is similar.
You don't rename the images, and drag them into the Assets.xcassets folder just as they are. Then you manually drag the thumbnails of your images into 2x slots. Here's an example with an image called 'gear':
For more information on how physical screen resolution of the iOS devices differs from its internal representation (which is in points), refer to this handy guide: https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
I’m new in iOS and trying to make simple app with hierarchy of viewcontrollers. In the last one I wanna display scrollable image (which can also be zoomed at least x1,5), containing some small black and white picture and a piece of text. Initially I planned to make vector image, convert it to .jpg and use UIScrollView for displaying. But I found out that .jpg ( approx. 150 KB) didn’t provide a good quality for displaying text. As I have to use a lot of images I don’t want to increase image size. What is worse I also want it look good on retina display.
Can you recommend a way how to display image, containing text, with enough quality?
I mean that I don’t want the user see the separate pixels of letters in the text. Just like when you read text in your e-mail in iOS. Image size should be as small as possible. Planning physical size of image – approx. 5 cm x 15 cm.
Any help much appreciated
Thanks
To get good edges you would need to use png not jpg, which will make the image sizes much larger. I have a better suggestion, more code but better solution.
The answer is to not put the text into the image, but to draw it over it in real time.
You would:
associate text at some coordinate in the image (say a CGRect) with the image
create a uiimageview subclass that in the drawRect routine, after calling super, draws the text using the NSString categories on UIKit (which let you draw into a context)
To get going on this please create a small one vc project and get the subclass working there, then back port it to your primary project.
I have over 100k in images that at one time were cropped and had a white border applied to them. I'm looking for the best way to programmaticly process each image so that I can detect the white borders and either crop the border or fill in the border with black instead. Would I need to use something like OpenCV or just plain old GDI? I've attached an image for reference.
What I have to work with (White borders are there, trust me):
http://cdn-images.hollywood.com/site/SO_3666231.jpg
Plain old GDI should work just fine, except for one thing - I don't know how to make GDI save an image back to a file. When I've had to do it in the past I've written a .BMP file in pieces, which wouldn't work for a JPEG. Time for a new question?
You're going to need a two step process - first measure the white borders, then copy the image to a new image to get rid of them.
Starting with a JPEG image introduces two small problems. First is that the image will contain some decoding artifacts, and white won't always be an RGB value of (255,255,255). You'll need to establish a threshold, such as (250,250,250) and see how that works; if it doesn't catch all of the borders, you'll need to try a lower threshold. Second is that resaving the image as a JPEG will introduce additional artifacts, lowering the quality of the image. Hopefully this will be within acceptable limits, but only you can be the judge of that.
I'm sorry that this isn't really an answer, perhaps more like 1/4 of an answer. I hope you find it useful.